361655 ExecutorThreadPool.isLowOnThreads() returns wrong value.

Optimized by calling getActiveCount() last, since it locks the thread pool.
This commit is contained in:
Simone Bordet 2011-10-21 22:53:20 +02:00
parent d4603e1fdd
commit 810223e259
1 changed files with 3 additions and 2 deletions

View File

@ -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;
}