Shutdown service executor

This commit is contained in:
M66B 2019-03-25 14:05:52 +00:00
parent 795b50ba5d
commit 7473697ac1
1 changed files with 52 additions and 50 deletions

View File

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