mirror of
https://github.com/M66B/FairEmail.git
synced 2026-03-31 14:17:03 +02:00
Core pool size
This commit is contained in:
@@ -281,6 +281,10 @@ public class Helper {
|
||||
}
|
||||
|
||||
static ExecutorService getBackgroundExecutor(int threads, final String name) {
|
||||
return getBackgroundExecutor(threads, threads, 0, name);
|
||||
}
|
||||
|
||||
static ExecutorService getBackgroundExecutor(int min, int max, int keepalive, final String name) {
|
||||
ThreadFactory factory = new ThreadFactory() {
|
||||
private final AtomicInteger threadId = new AtomicInteger();
|
||||
|
||||
@@ -293,7 +297,7 @@ public class Helper {
|
||||
}
|
||||
};
|
||||
|
||||
if (threads == 0) {
|
||||
if (max == 0) {
|
||||
// java.lang.OutOfMemoryError: pthread_create (1040KB stack) failed: Try again
|
||||
// 1040 KB native stack size / 32 KB thread stack size ~ 32 threads
|
||||
int processors = Runtime.getRuntime().availableProcessors(); // Modern devices: 8
|
||||
@@ -304,11 +308,11 @@ public class Helper {
|
||||
3L, TimeUnit.SECONDS,
|
||||
new LinkedBlockingQueue<Runnable>(),
|
||||
factory);
|
||||
} else if (threads == 1)
|
||||
} else if (max == 1)
|
||||
return new ThreadPoolExecutorEx(
|
||||
name,
|
||||
threads, threads,
|
||||
0L, TimeUnit.MILLISECONDS,
|
||||
min, max,
|
||||
keepalive, TimeUnit.SECONDS,
|
||||
new PriorityBlockingQueue<Runnable>(10, new PriorityComparator()),
|
||||
factory) {
|
||||
private final AtomicLong sequenceId = new AtomicLong();
|
||||
@@ -327,8 +331,8 @@ public class Helper {
|
||||
else
|
||||
return new ThreadPoolExecutorEx(
|
||||
name,
|
||||
threads, threads,
|
||||
0L, TimeUnit.MILLISECONDS,
|
||||
min, max,
|
||||
keepalive, TimeUnit.SECONDS,
|
||||
new LinkedBlockingQueue<Runnable>(),
|
||||
factory);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user