svn commit: r1617808 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/concurrent/ExecutionPool.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1617808 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/concurrent/ExecutionPool.java

doogie-3
Author: doogie
Date: Wed Aug 13 19:37:49 2014
New Revision: 1617808

URL: http://svn.apache.org/r1617808
Log:
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();
         }