Add a helper method for auto adjusting the threadCount.
git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@1617808 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -63,15 +63,20 @@ public final class ExecutionPool {
|
||||
return new ExecutionPoolThreadFactory(group, namePrefix);
|
||||
}
|
||||
|
||||
public static ScheduledExecutorService getExecutor(ThreadGroup group, String namePrefix, int threadCount, boolean preStart) {
|
||||
public static int autoAdjustThreadCount(int threadCount) {
|
||||
if (threadCount == 0) {
|
||||
threadCount = 1;
|
||||
return 1;
|
||||
} else if (threadCount < 0) {
|
||||
int numCpus = Runtime.getRuntime().availableProcessors();
|
||||
threadCount = Math.abs(threadCount) * numCpus;
|
||||
return Math.abs(threadCount) * numCpus;
|
||||
} else {
|
||||
return threadCount;
|
||||
}
|
||||
}
|
||||
|
||||
public static ScheduledExecutorService getExecutor(ThreadGroup group, String namePrefix, int threadCount, boolean preStart) {
|
||||
ThreadFactory threadFactory = createThreadFactory(group, namePrefix);
|
||||
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(threadCount, threadFactory);
|
||||
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(autoAdjustThreadCount(threadCount), threadFactory);
|
||||
if (preStart) {
|
||||
executor.prestartAllCoreThreads();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user