From: fhanik Date: Sat, 14 Apr 2007 01:41:35 +0000 (+0000) Subject: Smarter executor, only create threads if no threads are available X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=d36b5d26e881e9ae7e7c4d7fb6ec3918faa747e7;p=tomcat7.0 Smarter executor, only create threads if no threads are available git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@528735 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/catalina/core/StandardThreadExecutor.java b/java/org/apache/catalina/core/StandardThreadExecutor.java index c2d383628..d8b62ff9f 100644 --- a/java/org/apache/catalina/core/StandardThreadExecutor.java +++ b/java/org/apache/catalina/core/StandardThreadExecutor.java @@ -219,10 +219,17 @@ public class StandardThreadExecutor implements Executor { } public boolean offer(Runnable o) { - if (parent != null && parent.getPoolSize() < parent.getMaximumPoolSize()) - return false; //force creation of new threads by rejecting the task - else - return super.offer(o); + //we can't do any checks + if (parent==null) return super.offer(o); + //we are maxed out on threads, simply queue the object + if (parent.getPoolSize() == parent.getMaximumPoolSize()) return super.offer(o); + //we have idle threads, just add it to the queue + //this is an approximation, so it could use some tuning + if (parent.getActiveCount()<(parent.getPoolSize())) return super.offer(o); + //if we have less threads than maximum force creation of a new thread + if (parent.getPoolSize()