Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=46997
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 9 Apr 2009 09:13:28 +0000 (09:13 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 9 Apr 2009 09:13:28 +0000 (09:13 +0000)
Code clean up
Patch provided by Jens Kapitza

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

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

index 01d428c..fc579e7 100644 (file)
@@ -30,7 +30,7 @@ import java.util.concurrent.TimeUnit;
  *
  */
 public class TaskQueue extends LinkedBlockingQueue<Runnable> {
-    ThreadPoolExecutor parent = null;
+    private ThreadPoolExecutor parent = null;
 
     public TaskQueue() {
         super();
@@ -59,15 +59,13 @@ public class TaskQueue extends LinkedBlockingQueue<Runnable> {
     }
 
     public boolean offer(Runnable 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);
+        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);
+        }
+
     }
 }