|
@ -1576,7 +1576,7 @@ public class ServiceSynchronize extends LifecycleService { |
|
|
state = new ServiceState(); |
|
|
state = new ServiceState(); |
|
|
|
|
|
|
|
|
main = new Thread(new Runnable() { |
|
|
main = new Thread(new Runnable() { |
|
|
private List<Thread> threads = new ArrayList<>(); |
|
|
|
|
|
|
|
|
private Map<Thread, ServiceState> threadState = new HashMap<>(); |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void run() { |
|
|
public void run() { |
|
@ -1613,11 +1613,12 @@ public class ServiceSynchronize extends LifecycleService { |
|
|
// Start monitoring accounts |
|
|
// Start monitoring accounts |
|
|
for (final EntityAccount account : accounts) { |
|
|
for (final EntityAccount account : accounts) { |
|
|
Log.i(Helper.TAG, account.host + "/" + account.user + " run"); |
|
|
Log.i(Helper.TAG, account.host + "/" + account.user + " run"); |
|
|
|
|
|
final ServiceState astate = new ServiceState(); |
|
|
Thread t = new Thread(new Runnable() { |
|
|
Thread t = new Thread(new Runnable() { |
|
|
@Override |
|
|
@Override |
|
|
public void run() { |
|
|
public void run() { |
|
|
try { |
|
|
try { |
|
|
monitorAccount(account, state); |
|
|
|
|
|
|
|
|
monitorAccount(account, astate); |
|
|
} catch (Throwable ex) { |
|
|
} catch (Throwable ex) { |
|
|
// Fall-safe |
|
|
// Fall-safe |
|
|
Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex)); |
|
|
Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex)); |
|
@ -1625,7 +1626,7 @@ public class ServiceSynchronize extends LifecycleService { |
|
|
} |
|
|
} |
|
|
}, "sync.account." + account.id); |
|
|
}, "sync.account." + account.id); |
|
|
t.start(); |
|
|
t.start(); |
|
|
threads.add(t); |
|
|
|
|
|
|
|
|
threadState.put(t, astate); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
EntityLog.log(ServiceSynchronize.this, "Main started"); |
|
|
EntityLog.log(ServiceSynchronize.this, "Main started"); |
|
@ -1640,11 +1641,16 @@ public class ServiceSynchronize extends LifecycleService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Stop monitoring accounts |
|
|
// Stop monitoring accounts |
|
|
for (Thread t : threads) { |
|
|
|
|
|
|
|
|
for (Thread t : threadState.keySet()) { |
|
|
|
|
|
ServiceState astate = threadState.get(t); |
|
|
|
|
|
synchronized (astate) { |
|
|
|
|
|
astate.running = false; |
|
|
|
|
|
astate.notifyAll(); |
|
|
|
|
|
} |
|
|
t.interrupt(); |
|
|
t.interrupt(); |
|
|
join(t); |
|
|
join(t); |
|
|
} |
|
|
} |
|
|
threads.clear(); |
|
|
|
|
|
|
|
|
threadState.clear(); |
|
|
|
|
|
|
|
|
// Stop monitoring outbox |
|
|
// Stop monitoring outbox |
|
|
lbm.unregisterReceiver(outboxReceiver); |
|
|
lbm.unregisterReceiver(outboxReceiver); |
|
|