Browse Source

Fixed start/stop synchronization

main
M66B 5 years ago
parent
commit
1044c737e8
1 changed files with 6 additions and 4 deletions
  1. +6
    -4
      app/src/main/java/eu/faircode/email/ServiceSynchronize.java

+ 6
- 4
app/src/main/java/eu/faircode/email/ServiceSynchronize.java View File

@ -79,6 +79,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.Semaphore;
import javax.mail.Address; import javax.mail.Address;
import javax.mail.AuthenticationFailedException; import javax.mail.AuthenticationFailedException;
@ -1035,7 +1036,7 @@ public class ServiceSynchronize extends LifecycleService {
try { try {
wl0.release(); wl0.release();
Thread.sleep(Long.MAX_VALUE);
state.semaphore.acquire();
} catch (InterruptedException ex) { } catch (InterruptedException ex) {
EntityLog.log(this, account.name + " waited running=" + state.running); EntityLog.log(this, account.name + " waited running=" + state.running);
} finally { } finally {
@ -2035,7 +2036,7 @@ public class ServiceSynchronize extends LifecycleService {
try { try {
yieldWakelock(); yieldWakelock();
wl.release(); wl.release();
Thread.sleep(Long.MAX_VALUE);
state.semaphore.acquire();
} catch (InterruptedException ex) { } catch (InterruptedException ex) {
Log.w(Helper.TAG, "main wait " + ex.toString()); Log.w(Helper.TAG, "main wait " + ex.toString());
} finally { } finally {
@ -2045,7 +2046,7 @@ public class ServiceSynchronize extends LifecycleService {
// Stop monitoring accounts // Stop monitoring accounts
for (ServiceState astate : threadState) { for (ServiceState astate : threadState) {
astate.running = false; astate.running = false;
astate.thread.interrupt();
astate.semaphore.release();
join(astate.thread); join(astate.thread);
} }
threadState.clear(); threadState.clear();
@ -2080,7 +2081,7 @@ public class ServiceSynchronize extends LifecycleService {
EntityLog.log(ServiceSynchronize.this, "Main stop"); EntityLog.log(ServiceSynchronize.this, "Main stop");
state.running = false; state.running = false;
state.thread.interrupt();
state.semaphore.release();
join(state.thread); join(state.thread);
EntityLog.log(ServiceSynchronize.this, "Main stopped"); EntityLog.log(ServiceSynchronize.this, "Main stopped");
@ -2214,5 +2215,6 @@ public class ServiceSynchronize extends LifecycleService {
private class ServiceState { private class ServiceState {
boolean running = true; boolean running = true;
Thread thread; Thread thread;
Semaphore semaphore = new Semaphore(0);
} }
} }

Loading…
Cancel
Save