Core pool size

This commit is contained in:
M66B
2022-12-28 08:48:10 +01:00
parent 0ac085f93e
commit 8ffe2a7aea
2 changed files with 11 additions and 7 deletions

View File

@@ -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);
}