svn commit: r1617810 - in /ofbiz/trunk/framework: base/src/org/ofbiz/base/concurrent/ base/src/org/ofbiz/base/concurrent/test/ catalina/src/org/ofbiz/catalina/container/ entity/src/org/ofbiz/entity/datasource/

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

svn commit: r1617810 - in /ofbiz/trunk/framework: base/src/org/ofbiz/base/concurrent/ base/src/org/ofbiz/base/concurrent/test/ catalina/src/org/ofbiz/catalina/container/ entity/src/org/ofbiz/entity/datasource/

doogie-3
Author: doogie
Date: Wed Aug 13 19:38:12 2014
New Revision: 1617810

URL: http://svn.apache.org/r1617810
Log:
Add a GLOBAL_BATCH thread pool.  This is different than GLOBAL_EXECUTOR,
in that:

* BATCH does not block when all the coreThreads are busy, as would
  happen with EXECUTOR.  When all coreThreads are busy, new threads will
  be spawned.
* Scheduled jobs can *not* be submitted.

You can simulate the first problem, by modifying ExecutionPool, and
force-setting the threadCount to 1.  Then, submit something to the pool,
that will then itself submit more items into the pool.  Dead-lock will
occur.

BATCH should be used when it might be posslbe that more items could be
submitted by code you are calling.

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
    ofbiz/trunk/framework/catalina/src/org/ofbiz/catalina/container/CatalinaContainer.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/MemoryHelper.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=1617810&r1=1617809&r2=1617810&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:38:12 2014
@@ -24,11 +24,14 @@ import java.util.List;
 import java.util.concurrent.DelayQueue;
 import java.util.concurrent.Delayed;
 import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Future;
 import java.util.concurrent.ForkJoinPool;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.SynchronousQueue;
 import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
 
 import javolution.util.FastList;
@@ -39,7 +42,8 @@ import org.ofbiz.base.util.Debug;
 @SourceMonitored
 public final class ExecutionPool {
     public static final String module = ExecutionPool.class.getName();
-    public static final ScheduledExecutorService GLOBAL_EXECUTOR = getExecutor(null, "OFBiz-config", -1, false);
+    public static final ExecutorService GLOBAL_BATCH = getPooledExecutor(null, "OFBiz-batch", -1, Integer.MAX_VALUE, false);
+    public static final ScheduledExecutorService GLOBAL_EXECUTOR = getScheduledExecutor(null, "OFBiz-config", -1, false);
     public static final ForkJoinPool GLOBAL_FORK_JOIN = getForkJoinPool(-1);
 
     protected static class ExecutionPoolThreadFactory implements ThreadFactory {
@@ -76,7 +80,12 @@ public final class ExecutionPool {
         }
     }
 
+    @Deprecated
     public static ScheduledExecutorService getExecutor(ThreadGroup group, String namePrefix, int threadCount, boolean preStart) {
+        return getScheduledExecutor(group, namePrefix, threadCount, preStart);
+    }
+
+    public static ScheduledExecutorService getScheduledExecutor(ThreadGroup group, String namePrefix, int threadCount, boolean preStart) {
         ThreadFactory threadFactory = createThreadFactory(group, namePrefix);
         ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(autoAdjustThreadCount(threadCount), threadFactory);
         if (preStart) {
@@ -85,6 +94,15 @@ public final class ExecutionPool {
         return executor;
     }
 
+    public static ExecutorService getPooledExecutor(ThreadGroup group, String namePrefix, int threadCount, int maximumPoolSize, boolean preStart) {
+        ThreadFactory threadFactory = createThreadFactory(group, namePrefix);
+        ThreadPoolExecutor executor = new ThreadPoolExecutor(autoAdjustThreadCount(threadCount), maximumPoolSize, 5, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), threadFactory);
+        if (preStart) {
+            executor.prestartAllCoreThreads();
+        }
+        return executor;
+    }
+
     public static ForkJoinPool getForkJoinPool(int threadCount) {
         return new ForkJoinPool(autoAdjustThreadCount(threadCount));
     }

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=1617810&r1=1617809&r2=1617810&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 Wed Aug 13 19:38:12 2014
@@ -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.getExecutor(new ThreadGroup("TTLObject"), "TTLObject(async-update)", -2, true);
+    private static final ScheduledExecutorService updateExecutor = ExecutionPool.getScheduledExecutor(new ThreadGroup("TTLObject"), "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=1617810&r1=1617809&r2=1617810&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 Wed Aug 13 19:38:12 2014
@@ -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.getExecutor(new ThreadGroup("DependencyPoolTests"), getName(), -2, true);
+        ScheduledExecutorService executor = ExecutionPool.getScheduledExecutor(new ThreadGroup("DependencyPoolTests"), 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=1617810&r1=1617809&r2=1617810&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 Wed Aug 13 19:38:12 2014
@@ -53,7 +53,7 @@ public abstract class TTLObjectTest exte
 
     @Override
     protected void setUp() throws InterruptedException {
-        executor = ExecutionPool.getExecutor(new ThreadGroup("TTLObjectTest"), getName(), -1, true);
+        executor = ExecutionPool.getScheduledExecutor(new ThreadGroup("TTLObjectTest"), getName(), -1, true);
     }
 
     @Override

Modified: ofbiz/trunk/framework/catalina/src/org/ofbiz/catalina/container/CatalinaContainer.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/catalina/src/org/ofbiz/catalina/container/CatalinaContainer.java?rev=1617810&r1=1617809&r2=1617810&view=diff
==============================================================================
--- ofbiz/trunk/framework/catalina/src/org/ofbiz/catalina/container/CatalinaContainer.java (original)
+++ ofbiz/trunk/framework/catalina/src/org/ofbiz/catalina/container/CatalinaContainer.java Wed Aug 13 19:38:12 2014
@@ -737,7 +737,7 @@ public class CatalinaContainer implement
             return;
         }
 
-        ScheduledExecutorService executor = ExecutionPool.getExecutor(CATALINA_THREAD_GROUP, "catalina-startup", -1, true);
+        ScheduledExecutorService executor = ExecutionPool.getScheduledExecutor(CATALINA_THREAD_GROUP, "catalina-startup", -1, true);
         try {
             List<Future<Context>> futures = FastList.newInstance();
 

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java?rev=1617810&r1=1617809&r2=1617810&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java Wed Aug 13 19:38:12 2014
@@ -96,7 +96,7 @@ public class GenericDAO {
         this.helperInfo = helperInfo;
         this.modelFieldTypeReader = ModelFieldTypeReader.getModelFieldTypeReader(helperInfo.getHelperBaseName());
         this.datasource = EntityConfigUtil.getDatasource(helperInfo.getHelperBaseName());
-        this.executor = ExecutionPool.getExecutor(GENERIC_DAO_THREAD_GROUP, "OFBiz-entity-datasource(" + helperInfo.getHelperFullName() + ")", datasource.getMaxWorkerPoolSize(), false);
+        this.executor = ExecutionPool.getScheduledExecutor(GENERIC_DAO_THREAD_GROUP, "OFBiz-entity-datasource(" + helperInfo.getHelperFullName() + ")", datasource.getMaxWorkerPoolSize(), false);
     }
 
     public <T> Future<T> submitWork(Callable<T> callable) throws GenericEntityException {

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/MemoryHelper.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/MemoryHelper.java?rev=1617810&r1=1617809&r2=1617810&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/MemoryHelper.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/MemoryHelper.java Wed Aug 13 19:38:12 2014
@@ -282,7 +282,7 @@ public class MemoryHelper implements Gen
         this.helperName = helperName;
         modelFieldTypeReader = ModelFieldTypeReader.getModelFieldTypeReader(helperName);
         Datasource datasourceInfo = EntityConfigUtil.getDatasource(helperName);
-        this.executor = ExecutionPool.getExecutor(MEMORY_HELPER_THREAD_GROUP, "OFBiz-entity-datasource(" + helperName + ")", datasourceInfo.getMaxWorkerPoolSize(), false);
+        this.executor = ExecutionPool.getScheduledExecutor(MEMORY_HELPER_THREAD_GROUP, "OFBiz-entity-datasource(" + helperName + ")", datasourceInfo.getMaxWorkerPoolSize(), false);
     }
 
     public String getHelperName() {