svn commit: r1139697 - in /ofbiz/trunk/framework/base/src/org/ofbiz/base/concurrent: ExecutionPool.java TTLObject.java test/DependencyPoolTests.java test/TTLObjectTest.java

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

svn commit: r1139697 - in /ofbiz/trunk/framework/base/src/org/ofbiz/base/concurrent: ExecutionPool.java TTLObject.java test/DependencyPoolTests.java test/TTLObjectTest.java

doogie-3
Author: doogie
Date: Sun Jun 26 02:50:29 2011
New Revision: 1139697

URL: http://svn.apache.org/viewvc?rev=1139697&view=rev
Log:
FEATURE: if the threadCount passed to getExecutor is negative, then use
the abs() value of that times the number of cpus, to specify the actual
number of threads.

Modified:
    ofbiz/trunk/framework/base/src/org/ofbiz/base/concurrent/ExecutionPool.java
    ofbiz/trunk/framework/base/src/org/ofbiz/base/concurrent/TTLObject.java
    ofbiz/trunk/framework/base/src/org/ofbiz/base/concurrent/test/DependencyPoolTests.java
    ofbiz/trunk/framework/base/src/org/ofbiz/base/concurrent/test/TTLObjectTest.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=1139697&r1=1139696&r2=1139697&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 Sun Jun 26 02:50:29 2011
@@ -58,6 +58,12 @@ public final class ExecutionPool {
     }
 
     public static ScheduledExecutorService getExecutor(String namePrefix, int threadCount, boolean preStart) {
+        if (threadCount == 0) {
+            threadCount = 1;
+        } else if (threadCount < 0) {
+            int numCpus = ManagementFactory.getOperatingSystemMXBean().getAvailableProcessors();
+            threadCount = Math.abs(threadCount) * numCpus;
+        }
         ThreadFactory threadFactory = createThreadFactory(namePrefix);
         ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(threadCount, threadFactory);
         if (preStart) {
@@ -66,12 +72,14 @@ public final class ExecutionPool {
         return executor;
     }
 
+    @Deprecated
     public static ScheduledExecutorService getNewExactExecutor(String namePrefix) {
-        return getExecutor(namePrefix, ManagementFactory.getOperatingSystemMXBean().getAvailableProcessors());
+        return getExecutor(namePrefix, -1, true);
     }
 
+    @Deprecated
     public static ScheduledExecutorService getNewOptimalExecutor(String namePrefix) {
-        return getExecutor(namePrefix, ManagementFactory.getOperatingSystemMXBean().getAvailableProcessors() * 2);
+        return getExecutor(namePrefix, -2, true);
     }
 
     public static void addPulse(Pulse pulse) {

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/concurrent/TTLObject.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/concurrent/TTLObject.java?rev=1139697&r1=1139696&r2=1139697&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/concurrent/TTLObject.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/concurrent/TTLObject.java Sun Jun 26 02:50:29 2011
@@ -33,7 +33,7 @@ import org.ofbiz.base.util.UtilGenerics;
 
 @SourceMonitored
 public abstract class TTLObject<T> implements ObjectWrapper<T> {
-    private static final ScheduledExecutorService updateExecutor = ExecutionPool.getNewOptimalExecutor("TTLObject(async-update)");
+    private static final ScheduledExecutorService updateExecutor = ExecutionPool.getExecutor("TTLObject(async-update)", -2, true);
 
     private static final <T> T getConfigForClass(ConcurrentHashMap<String, T> config, Class<?> c) {
         Class<?> ptr = c;

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/concurrent/test/DependencyPoolTests.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/concurrent/test/DependencyPoolTests.java?rev=1139697&r1=1139696&r2=1139697&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/concurrent/test/DependencyPoolTests.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/concurrent/test/DependencyPoolTests.java Sun Jun 26 02:50:29 2011
@@ -36,7 +36,7 @@ public class DependencyPoolTests extends
 
     public void testDependencyPool() throws Exception {
         // always use more threads than cpus, so that the single-cpu case can be tested
-        ScheduledExecutorService executor = ExecutionPool.getNewOptimalExecutor(getName());
+        ScheduledExecutorService executor = ExecutionPool.getExecutor(getName(), -2, true);
         DependencyPool<Integer, TestItem, String> pool = new DependencyPool<Integer, TestItem, String>(executor);
         int itemSize = 100, depMax = 5, subMax = 3;
         List<TestItem> items = new ArrayList<TestItem>(itemSize);

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/concurrent/test/TTLObjectTest.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/concurrent/test/TTLObjectTest.java?rev=1139697&r1=1139696&r2=1139697&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/concurrent/test/TTLObjectTest.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/concurrent/test/TTLObjectTest.java Sun Jun 26 02:50:29 2011
@@ -53,7 +53,7 @@ public abstract class TTLObjectTest exte
 
     @Override
     protected void setUp() throws InterruptedException {
-        executor = ExecutionPool.getNewExactExecutor(getName());
+        executor = ExecutionPool.getExecutor(getName(), -1, true);
     }
 
     @Override