Author: jacopoc
Date: Tue Sep 23 10:52:29 2014 New Revision: 1626977 URL: http://svn.apache.org/r1626977 Log: Removed a bunch of never used classes from the base/concurrent package. Provided better settings for the thread pools to avoid to keep alive threads that are only needed at startup. Removed: ofbiz/trunk/framework/base/src/org/ofbiz/base/concurrent/DependencyPool.java ofbiz/trunk/framework/base/src/org/ofbiz/base/concurrent/GeneratedResult.java ofbiz/trunk/framework/base/src/org/ofbiz/base/concurrent/TTLCachedObject.java ofbiz/trunk/framework/base/src/org/ofbiz/base/concurrent/TTLObject.java ofbiz/trunk/framework/base/src/org/ofbiz/base/concurrent/test/ ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/ObjectWrapper.java Modified: ofbiz/trunk/framework/base/build.xml ofbiz/trunk/framework/base/src/org/ofbiz/base/concurrent/ExecutionPool.java ofbiz/trunk/framework/base/testdef/basetests.xml ofbiz/trunk/framework/entity/src/org/ofbiz/entity/DelegatorFactory.java Modified: ofbiz/trunk/framework/base/build.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/build.xml?rev=1626977&r1=1626976&r2=1626977&view=diff ============================================================================== --- ofbiz/trunk/framework/base/build.xml (original) +++ ofbiz/trunk/framework/base/build.xml Tue Sep 23 10:52:29 2014 @@ -54,10 +54,6 @@ under the License. <file name="org/ofbiz/base/util/test/UtilIOTests.java"/> <file name="org/ofbiz/base/test/BaseUnitTests.java"/> <file name="org/ofbiz/base/util/collections/test/GenericMapTest.java"/> - <file name="org/ofbiz/base/concurrent/test/DependencyPoolTests.java"/> - <file name="org/ofbiz/base/concurrent/test/SyncTTLObjectTest.java"/> - <file name="org/ofbiz/base/concurrent/test/AsyncTTLObjectTest.java"/> - <file name="org/ofbiz/base/concurrent/test/TTLCachedObjectTest.java"/> </filelist> <patternset id="cobertura-src-dirs"> 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=1626977&r1=1626976&r2=1626977&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 Tue Sep 23 10:52:29 2014 @@ -19,7 +19,6 @@ package org.ofbiz.base.concurrent; import java.util.Collection; -import java.util.Iterator; import java.util.List; import java.util.concurrent.DelayQueue; import java.util.concurrent.Delayed; @@ -42,14 +41,13 @@ import org.ofbiz.base.util.Debug; @SourceMonitored public final class ExecutionPool { public static final String module = ExecutionPool.class.getName(); - 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); + public static final ExecutorService GLOBAL_BATCH = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 5, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), new ExecutionPoolThreadFactory(null, "OFBiz-batch")); + public static final ForkJoinPool GLOBAL_FORK_JOIN = new ForkJoinPool(); protected static class ExecutionPoolThreadFactory implements ThreadFactory { private final ThreadGroup group; private final String namePrefix; - private int count = 0; + private volatile int count = 1; protected ExecutionPoolThreadFactory(ThreadGroup group, String namePrefix) { this.group = group; @@ -65,11 +63,7 @@ public final class ExecutionPool { } } - public static ThreadFactory createThreadFactory(ThreadGroup group, String namePrefix) { - return new ExecutionPoolThreadFactory(group, namePrefix); - } - - public static int autoAdjustThreadCount(int threadCount) { + private static int autoAdjustThreadCount(int threadCount) { if (threadCount == 0) { return 1; } else if (threadCount < 0) { @@ -80,33 +74,21 @@ 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) { - executor.prestartAllCoreThreads(); - } - return executor; + return getScheduledExecutor(group, namePrefix, threadCount, 0, preStart); } - - 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); + public static ScheduledExecutorService getScheduledExecutor(ThreadGroup group, String namePrefix, int threadCount, long keepAliveSeconds, boolean preStart) { + ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(autoAdjustThreadCount(threadCount), new ExecutionPoolThreadFactory(group, namePrefix)); + if (keepAliveSeconds > 0) { + executor.setKeepAliveTime(keepAliveSeconds, TimeUnit.SECONDS); + executor.allowCoreThreadTimeOut(true); + } if (preStart) { executor.prestartAllCoreThreads(); } return executor; } - public static ForkJoinPool getForkJoinPool(int threadCount) { - return new ForkJoinPool(autoAdjustThreadCount(threadCount)); - } - public static <F> List<F> getAllFutures(Collection<Future<F>> futureList) { List<F> result = FastList.newInstance(); for (Future<F> future: futureList) { @@ -129,17 +111,6 @@ public final class ExecutionPool { delayQueue.remove(pulse); } - public static void pulseAll(Class<? extends Pulse> match) { - Iterator<Pulse> it = delayQueue.iterator(); - while (it.hasNext()) { - Pulse pulse = it.next(); - if (match.isInstance(pulse)) { - it.remove(); - pulse.run(); - } - } - } - static { ExecutionPoolPulseWorker worker = new ExecutionPoolPulseWorker(); int processorCount = Runtime.getRuntime().availableProcessors(); Modified: ofbiz/trunk/framework/base/testdef/basetests.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/testdef/basetests.xml?rev=1626977&r1=1626976&r2=1626977&view=diff ============================================================================== --- ofbiz/trunk/framework/base/testdef/basetests.xml (original) +++ ofbiz/trunk/framework/base/testdef/basetests.xml Tue Sep 23 10:52:29 2014 @@ -32,7 +32,6 @@ <junit-test-suite class-name="org.ofbiz.base.util.cache.test.UtilCacheTests"/> <junit-test-suite class-name="org.ofbiz.base.conversion.test.DateTimeTests"/> <junit-test-suite class-name="org.ofbiz.base.conversion.test.MiscTests"/> - <junit-test-suite class-name="org.ofbiz.base.concurrent.test.DependencyPoolTests"/> <junit-test-suite class-name="org.ofbiz.base.json.test.JSONTests"/> <!--junit-test-suite class-name="org.ofbiz.base.util.test.UtilIOTests"/--> <junit-test-suite class-name="org.ofbiz.base.test.BaseUnitTests"/> Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/DelegatorFactory.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/DelegatorFactory.java?rev=1626977&r1=1626976&r2=1626977&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/DelegatorFactory.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/DelegatorFactory.java Tue Sep 23 10:52:29 2014 @@ -36,7 +36,7 @@ public abstract class DelegatorFactory i public static final String module = DelegatorFactoryImpl.class.getName(); private static final ConcurrentHashMap<String, Future<Delegator>> delegators = new ConcurrentHashMap<String, Future<Delegator>>(); private static final ThreadGroup DELEGATOR_THREAD_GROUP = new ThreadGroup("DelegatorFactory"); - private static final ScheduledExecutorService executor = ExecutionPool.getScheduledExecutor(DELEGATOR_THREAD_GROUP, "delegator-startup", -1, true); + private static final ScheduledExecutorService executor = ExecutionPool.getScheduledExecutor(DELEGATOR_THREAD_GROUP, "delegator-startup", -1, 10, true); public static Delegator getDelegator(String delegatorName) { Future<Delegator> future = getDelegatorFuture(delegatorName); |
Free forum by Nabble | Edit this page |