You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by fh...@apache.org on 2007/04/14 03:41:36 UTC

svn commit: r528735 - in /tomcat/tc6.0.x/trunk/java/org/apache: catalina/core/StandardThreadExecutor.java tomcat/util/net/NioEndpoint.java

Author: fhanik
Date: Fri Apr 13 18:41:35 2007
New Revision: 528735

URL: http://svn.apache.org/viewvc?view=rev&rev=528735
Log:
Smarter executor, only create threads if no threads are available

Modified:
    tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/StandardThreadExecutor.java
    tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java

Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/StandardThreadExecutor.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/StandardThreadExecutor.java?view=diff&rev=528735&r1=528734&r2=528735
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/StandardThreadExecutor.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/StandardThreadExecutor.java Fri Apr 13 18:41:35 2007
@@ -219,10 +219,17 @@
         }
 
         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()<parent.getMaximumPoolSize()) return false;
+            //if we reached here, we need to add it to the queue
+            return super.offer(o);
         }
     }
 

Modified: tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java?view=diff&rev=528735&r1=528734&r2=528735
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Fri Apr 13 18:41:35 2007
@@ -2153,8 +2153,17 @@
         }
         
         public boolean offer(Runnable o) {
-            if ( parent != null && parent.getPoolSize()<parent.getMaximumPoolSize() ) return false;//force creation of new threads
-            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()<parent.getMaximumPoolSize()) return false;
+            //if we reached here, we need to add it to the queue
+            return super.offer(o);
         }
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org