Shutdown service executor

pull/153/head
M66B 6 years ago
parent 795b50ba5d
commit 7473697ac1

@ -51,6 +51,7 @@ import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.RejectedExecutionException;
import javax.mail.FetchProfile;
import javax.mail.Folder;
@ -155,16 +156,11 @@ public class ServiceSynchronize extends LifecycleService {
@Override
public void onDestroy() {
Log.i("Service destroy");
EntityLog.log(this, "Service destroy");
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
cm.unregisterNetworkCallback(networkCallback);
synchronized (this) {
EntityLog.log(this, "Service destroy");
if (started)
queue_reload(false, "service destroy");
}
Widget.update(this, -1);
WorkerCleanup.cancel();
@ -305,6 +301,7 @@ public class ServiceSynchronize extends LifecycleService {
started = doStart;
try {
queued++;
queue.submit(new Runnable() {
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
@ -344,19 +341,24 @@ public class ServiceSynchronize extends LifecycleService {
queued--;
EntityLog.log(ServiceSynchronize.this, "Reload done queued=" + queued);
if (queued == 0 && !isEnabled()) {
if (!doStart && queued == 0 && !isEnabled()) {
try {
Thread.sleep(STOP_DELAY);
} catch (InterruptedException ignored) {
}
if (queued == 0 && !isEnabled())
if (!doStart && queued == 0 && !isEnabled()) {
queue.shutdownNow();
stopService();
}
}
wl.release();
}
}
});
} catch (RejectedExecutionException ex) {
Log.w(ex);
}
}
private boolean isEnabled() {

Loading…
Cancel
Save