svn commit: r1139698 - 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: r1139698 - 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:35 2011
New Revision: 1139698

URL: http://svn.apache.org/viewvc?rev=1139698&view=rev
Log:
FEATURE: Allow the ThreadGroup to be specified for created 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=1139698&r1=1139697&r2=1139698&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:35 2011
@@ -32,15 +32,17 @@ import org.ofbiz.base.lang.SourceMonitor
 @SourceMonitored
 public final class ExecutionPool {
     protected static class ExecutionPoolThreadFactory implements ThreadFactory {
+        private final ThreadGroup group;
         private final String namePrefix;
         private int count = 0;
 
-        protected ExecutionPoolThreadFactory(String namePrefix) {
+        protected ExecutionPoolThreadFactory(ThreadGroup group, String namePrefix) {
+            this.group = group;
             this.namePrefix = namePrefix;
         }
 
         public Thread newThread(Runnable r) {
-            Thread t = new Thread(r);
+            Thread t = new Thread(group, r);
             t.setDaemon(true);
             t.setPriority(Thread.NORM_PRIORITY);
             t.setName(namePrefix + "-" + count++);
@@ -48,23 +50,28 @@ public final class ExecutionPool {
         }
     }
 
+    @Deprecated
     public static ThreadFactory createThreadFactory(String namePrefix) {
-        return new ExecutionPoolThreadFactory(namePrefix);
+        return createThreadFactory(null, namePrefix);
+    }
+
+    public static ThreadFactory createThreadFactory(ThreadGroup group, String namePrefix) {
+        return new ExecutionPoolThreadFactory(group, namePrefix);
     }
 
     @Deprecated
     public static ScheduledExecutorService getExecutor(String namePrefix, int threadCount) {
-        return getExecutor(namePrefix, threadCount, true);
+        return getExecutor(null, namePrefix, threadCount, true);
     }
 
-    public static ScheduledExecutorService getExecutor(String namePrefix, int threadCount, boolean preStart) {
+    public static ScheduledExecutorService getExecutor(ThreadGroup group, 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);
+        ThreadFactory threadFactory = createThreadFactory(group, namePrefix);
         ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(threadCount, threadFactory);
         if (preStart) {
             executor.prestartAllCoreThreads();
@@ -74,12 +81,12 @@ public final class ExecutionPool {
 
     @Deprecated
     public static ScheduledExecutorService getNewExactExecutor(String namePrefix) {
-        return getExecutor(namePrefix, -1, true);
+        return getExecutor(null, namePrefix, -1, true);
     }
 
     @Deprecated
     public static ScheduledExecutorService getNewOptimalExecutor(String namePrefix) {
-        return getExecutor(namePrefix, -2, true);
+        return getExecutor(null, 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=1139698&r1=1139697&r2=1139698&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:35 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.getExecutor("TTLObject(async-update)", -2, true);
+    private static final ScheduledExecutorService updateExecutor = ExecutionPool.getExecutor(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=1139698&r1=1139697&r2=1139698&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:35 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.getExecutor(getName(), -2, true);
+        ScheduledExecutorService executor = ExecutionPool.getExecutor(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=1139698&r1=1139697&r2=1139698&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:35 2011
@@ -53,7 +53,7 @@ public abstract class TTLObjectTest exte
 
     @Override
     protected void setUp() throws InterruptedException {
-        executor = ExecutionPool.getExecutor(getName(), -1, true);
+        executor = ExecutionPool.getExecutor(new ThreadGroup("TTLObjectTest"), getName(), -1, true);
     }
 
     @Override