Revert http://svn.apache.org/viewvc?view=rev&revision=763566
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 9 Jun 2009 18:51:07 +0000 (18:51 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 9 Jun 2009 18:51:07 +0000 (18:51 +0000)
The code is not the same as it was before. The patch applied, while it looks the same will grow the pool the max threads even though it doesn't need to

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@783094 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/tomcat/util/threads/TaskQueue.java

index fc579e7..707776c 100644 (file)
@@ -59,13 +59,15 @@ public class TaskQueue extends LinkedBlockingQueue<Runnable> {
     }
 
     public boolean offer(Runnable o) {
-        if (parent != null && parent.getPoolSize()<parent.getMaximumPoolSize()){
-               return false;
-        } else {
-            //if we reached here, we need to add it to the queue
-            //or can't do any checks
-            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
+        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);
     }
 }