diff options
author | Eike Stepper | 2015-12-18 09:55:25 +0000 |
---|---|---|
committer | Eike Stepper | 2015-12-18 09:55:25 +0000 |
commit | 35dfd3f3110824a47bb7f692705a7055699e94f6 (patch) | |
tree | 84e2bf66948bd5a2dc673b5985317e9fb65cb76b | |
parent | 733aaabd8b1ccb6c41a3543f43f9324c45c912c1 (diff) | |
download | cdo-35dfd3f3110824a47bb7f692705a7055699e94f6.tar.gz cdo-35dfd3f3110824a47bb7f692705a7055699e94f6.tar.xz cdo-35dfd3f3110824a47bb7f692705a7055699e94f6.zip |
[475039] Enhance ThreadPool and use it as much as possible
Do not enqueue the new runnable command if we can create a new worker
thread and there's currently no idle thread.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=475039
-rw-r--r-- | plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/Config.java | 4 | ||||
-rw-r--r-- | plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/concurrent/ThreadPool.java | 10 |
2 files changed, 9 insertions, 5 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/Config.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/Config.java index fa6c869e38..522a0892ac 100644 --- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/Config.java +++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/Config.java @@ -26,9 +26,7 @@ public abstract class Config implements IConfig { private static final long serialVersionUID = 1L; - private static final int MAXIMUM_POOL_SIZE = 1000; - - protected static ExecutorService executorService = ThreadPool.create("test", 20, MAXIMUM_POOL_SIZE, 10); + protected static ExecutorService executorService = ThreadPool.create("test", 10, 1000, 10); private String name; diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/concurrent/ThreadPool.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/concurrent/ThreadPool.java index 9b16746460..ff52458685 100644 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/concurrent/ThreadPool.java +++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/concurrent/ThreadPool.java @@ -216,8 +216,11 @@ public class ThreadPool extends ThreadPoolExecutor implements RejectedExecutionH @Override public boolean offer(Runnable runnable) { - if (threadPool.getPoolSize() < threadPool.getMaximumPoolSize()) + int poolSize = threadPool.getPoolSize(); + if (poolSize < threadPool.getMaximumPoolSize() && poolSize == threadPool.getActiveCount()) { + // Do not enqueue the new runnable command if we can create a new worker thread and there's currently no idle + // thread. return false; } @@ -259,8 +262,11 @@ public class ThreadPool extends ThreadPoolExecutor implements RejectedExecutionH public boolean offer(Runnable r) { - if (threadPool.getPoolSize() < threadPool.getMaximumPoolSize()) + int poolSize = threadPool.getPoolSize(); + if (poolSize < threadPool.getMaximumPoolSize() && poolSize == threadPool.getActiveCount()) { + // Do not enqueue the new runnable command if we can create a new worker thread and there's currently no idle + // thread. return false; } |