From 7247d178a396d1e74eb6a1fd23643d3c0d5c9c34 Mon Sep 17 00:00:00 2001 From: fhanik Date: Tue, 13 Mar 2007 22:28:33 +0000 Subject: [PATCH] Use a thread pool executor by default. This makes tomcat a little bit slower, but it handles load distribution a lot better than the current thread pool git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@517913 13f79535-47bb-0310-9956-ffa450edef68 --- java/org/apache/tomcat/util/net/NioEndpoint.java | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/java/org/apache/tomcat/util/net/NioEndpoint.java b/java/org/apache/tomcat/util/net/NioEndpoint.java index 16ff924fb..40457f6fd 100644 --- a/java/org/apache/tomcat/util/net/NioEndpoint.java +++ b/java/org/apache/tomcat/util/net/NioEndpoint.java @@ -48,6 +48,9 @@ import org.apache.tomcat.util.res.StringManager; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.CountDownLatch; import java.util.Comparator; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.LinkedBlockingQueue; /** * NIO tailored thread pool, providing the following services: @@ -650,8 +653,8 @@ public class NioEndpoint { // Create worker collection if (executor == null) { - workers = new WorkerStack(maxThreads); - //executor = new ThreadPoolExecutor(getMinSpareThreads(),getMaxThreads(),5000,TimeUnit.MILLISECONDS,new LinkedBlockingQueue()); + //workers = new WorkerStack(maxThreads); + executor = new ThreadPoolExecutor(getMaxThreads(),getMaxThreads(),5000,TimeUnit.MILLISECONDS,new LinkedBlockingQueue()); } // Start acceptor threads @@ -859,16 +862,20 @@ public class NioEndpoint { * @return boolean */ protected boolean isWorkerAvailable() { - if (workers.size() > 0) { - return true; - } - if ((maxThreads > 0) && (curThreads < maxThreads)) { + if ( executor != null ) { return true; } else { - if (maxThreads < 0) { + if (workers.size() > 0) { + return true; + } + if ( (maxThreads > 0) && (curThreads < maxThreads)) { return true; } else { - return false; + if (maxThreads < 0) { + return true; + } else { + return false; + } } } } -- 2.11.0