mirror of https://github.com/M66B/FairEmail.git
Shutdown service executor
This commit is contained in:
parent
795b50ba5d
commit
7473697ac1
|
@ -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() {
|
||||||
|
|
Loading…
Reference in New Issue