Browse Source

Fixed occasional hangs on stop, small improvements

main
M66B 6 years ago
parent
commit
99a174f8c1
1 changed files with 10 additions and 7 deletions
  1. +10
    -7
      app/src/main/java/eu/faircode/email/ServiceSynchronize.java

+ 10
- 7
app/src/main/java/eu/faircode/email/ServiceSynchronize.java View File

@ -1549,6 +1549,7 @@ public class ServiceSynchronize extends LifecycleService {
private void start() { private void start() {
EntityLog.log(ServiceSynchronize.this, "Main start"); EntityLog.log(ServiceSynchronize.this, "Main start");
state = new ServiceState(); state = new ServiceState();
main = new Thread(new Runnable() { main = new Thread(new Runnable() {
@ -1556,9 +1557,9 @@ public class ServiceSynchronize extends LifecycleService {
@Override @Override
public void run() { public void run() {
DB db = DB.getInstance(ServiceSynchronize.this);
try { try {
DB db = DB.getInstance(ServiceSynchronize.this);
outbox = db.folder().getOutbox(); outbox = db.folder().getOutbox();
if (outbox == null) { if (outbox == null) {
EntityLog.log(ServiceSynchronize.this, "No outbox, halt"); EntityLog.log(ServiceSynchronize.this, "No outbox, halt");
@ -1604,11 +1605,12 @@ public class ServiceSynchronize extends LifecycleService {
threads.add(t); threads.add(t);
} }
EntityLog.log(ServiceSynchronize.this, "Main started " + main);
EntityLog.log(ServiceSynchronize.this, "Main started");
synchronized (state) { synchronized (state) {
try { try {
state.wait();
if (state.running)
state.wait();
} catch (InterruptedException ex) { } catch (InterruptedException ex) {
Log.w(Helper.TAG, "main wait " + ex.toString()); Log.w(Helper.TAG, "main wait " + ex.toString());
} }
@ -1638,7 +1640,8 @@ public class ServiceSynchronize extends LifecycleService {
} }
private void stop() { private void stop() {
EntityLog.log(ServiceSynchronize.this, "Main stop " + main);
EntityLog.log(ServiceSynchronize.this, "Main stop");
synchronized (state) { synchronized (state) {
state.running = false; state.running = false;
state.notifyAll(); state.notifyAll();
@ -1648,10 +1651,10 @@ public class ServiceSynchronize extends LifecycleService {
main.interrupt(); main.interrupt();
join(main); join(main);
EntityLog.log(ServiceSynchronize.this, "Main stopped");
main = null; main = null;
state = null; state = null;
EntityLog.log(ServiceSynchronize.this, "Main stopped " + main);
} }
private void restart() { private void restart() {


Loading…
Cancel
Save