Author: doogie
Date: Wed Aug 13 19:37:49 2014
New Revision: 1617808
URL:
http://svn.apache.org/r1617808Log:
Add a helper method for auto adjusting the threadCount.
Modified:
ofbiz/trunk/framework/base/src/org/ofbiz/base/concurrent/ExecutionPool.java
Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/concurrent/ExecutionPool.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/concurrent/ExecutionPool.java?rev=1617808&r1=1617807&r2=1617808&view=diff==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/concurrent/ExecutionPool.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/concurrent/ExecutionPool.java Wed Aug 13 19:37:49 2014
@@ -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();
}