From 810223e2591471d4cba024e30349fe9c9db961e2 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Fri, 21 Oct 2011 22:53:20 +0200 Subject: [PATCH] 361655 ExecutorThreadPool.isLowOnThreads() returns wrong value. Optimized by calling getActiveCount() last, since it locks the thread pool. --- .../org/eclipse/jetty/util/thread/ExecutorThreadPool.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ExecutorThreadPool.java b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ExecutorThreadPool.java index 3471a65dbc1..0934e7c24a1 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ExecutorThreadPool.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ExecutorThreadPool.java @@ -156,8 +156,9 @@ public class ExecutorThreadPool extends AbstractLifeCycle implements ThreadPool, if (_executor instanceof ThreadPoolExecutor) { final ThreadPoolExecutor tpe = (ThreadPoolExecutor)_executor; - int idleThreads = tpe.getPoolSize() - tpe.getActiveCount(); - return tpe.getPoolSize() == tpe.getMaximumPoolSize() && tpe.getQueue().size() >= idleThreads; + // getActiveCount() locks the thread pool, so execute it last + return tpe.getPoolSize() == tpe.getMaximumPoolSize() && + tpe.getQueue().size() >= tpe.getPoolSize() - tpe.getActiveCount(); } return false; }