mirror of
https://github.com/M66B/FairEmail.git
synced 2025-01-03 13:44:40 +00:00
Shutdown operations queue
This commit is contained in:
parent
586033fa7f
commit
16aa183b3f
2 changed files with 24 additions and 4 deletions
|
@ -163,12 +163,14 @@ public class Helper {
|
|||
|
||||
if (threads == 0)
|
||||
return new ThreadPoolExecutorEx(
|
||||
name,
|
||||
0, Integer.MAX_VALUE,
|
||||
60L, TimeUnit.SECONDS,
|
||||
new SynchronousQueue<Runnable>(),
|
||||
factory);
|
||||
else if (threads == 1)
|
||||
return new ThreadPoolExecutorEx(
|
||||
name,
|
||||
threads, threads,
|
||||
0L, TimeUnit.MILLISECONDS,
|
||||
new PriorityBlockingQueue<Runnable>(10, new PriorityComparator()),
|
||||
|
@ -184,6 +186,7 @@ public class Helper {
|
|||
};
|
||||
else
|
||||
return new ThreadPoolExecutorEx(
|
||||
name,
|
||||
threads, threads,
|
||||
0L, TimeUnit.MILLISECONDS,
|
||||
new LinkedBlockingQueue<Runnable>(),
|
||||
|
@ -191,14 +194,29 @@ public class Helper {
|
|||
}
|
||||
|
||||
private static class ThreadPoolExecutorEx extends ThreadPoolExecutor {
|
||||
public ThreadPoolExecutorEx(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory) {
|
||||
String name;
|
||||
|
||||
public ThreadPoolExecutorEx(
|
||||
String name,
|
||||
int corePoolSize, int maximumPoolSize,
|
||||
long keepAliveTime, TimeUnit unit,
|
||||
BlockingQueue<Runnable> workQueue,
|
||||
ThreadFactory threadFactory) {
|
||||
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory);
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void beforeExecute(Thread t, Runnable r) {
|
||||
Log.d("Executing " + t.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
Log.i("Shutdown " + name);
|
||||
super.getQueue().clear();
|
||||
super.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
private static class PriorityFuture<T> implements RunnableFuture<T> {
|
||||
|
|
|
@ -825,6 +825,9 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|||
}
|
||||
});
|
||||
|
||||
final ExecutorService executor =
|
||||
Helper.getBackgroundExecutor(1, "account_" + account.id);
|
||||
|
||||
final Map<EntityFolder, IMAPFolder> mapFolders = new HashMap<>();
|
||||
List<Thread> idlers = new ArrayList<>();
|
||||
try {
|
||||
|
@ -944,9 +947,6 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|||
Core.onSynchronizeFolders(this, account, iservice.getStore(), state);
|
||||
|
||||
// Open synchronizing folders
|
||||
final ExecutorService executor =
|
||||
Helper.getBackgroundExecutor(1, "account_" + account.id);
|
||||
|
||||
List<EntityFolder> folders = db.folder().getFolders(account.id, false, true);
|
||||
Collections.sort(folders, new Comparator<EntityFolder>() {
|
||||
@Override
|
||||
|
@ -1416,6 +1416,8 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|||
}
|
||||
});
|
||||
|
||||
executor.shutdown();
|
||||
|
||||
// Close folders
|
||||
for (EntityFolder folder : mapFolders.keySet())
|
||||
if (folder.synchronize && !folder.poll && mapFolders.get(folder) != null) {
|
||||
|
|
Loading…
Reference in a new issue