From 111f90c0574cb2247e4e9cf861cbeef4e7cb197b Mon Sep 17 00:00:00 2001 From: Adam Heath Date: Wed, 13 Aug 2014 19:37:49 +0000 Subject: [PATCH] Add a helper method for auto adjusting the threadCount. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@1617808 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/ofbiz/base/concurrent/ExecutionPool.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/framework/base/src/org/ofbiz/base/concurrent/ExecutionPool.java b/framework/base/src/org/ofbiz/base/concurrent/ExecutionPool.java index 33734c8ffc..0abfd98dc8 100644 --- a/framework/base/src/org/ofbiz/base/concurrent/ExecutionPool.java +++ b/framework/base/src/org/ofbiz/base/concurrent/ExecutionPool.java @@ -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(); }