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/03/22 02:21:26 UTC

svn commit: r521068 - /tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/StandardThreadExecutor.java

Author: fhanik
Date: Wed Mar 21 18:21:25 2007
New Revision: 521068

URL: http://svn.apache.org/viewvc?view=rev&rev=521068
Log:
Make sure that we don't need to use any locks or synchronized statements to get our executor to work properly.
If the task gets executed, means that the threadpool just reached max threads when we were about to add this one in.
a simple race condition that we can take care of easily

Modified:
    tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/StandardThreadExecutor.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=521068&r1=521067&r2=521068
==============================================================================
--- 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 Wed Mar 21 18:21:25 2007
@@ -11,6 +11,7 @@
 import org.apache.catalina.LifecycleException;
 import org.apache.catalina.LifecycleListener;
 import org.apache.catalina.util.LifecycleSupport;
+import java.util.concurrent.RejectedExecutionException;
 
 public class StandardThreadExecutor implements Executor {
     
@@ -59,8 +60,14 @@
     }
     
     public void execute(Runnable command) {
-        if ( executor != null ) executor.execute(command);
-        else throw new IllegalStateException("StandardThreadPool not started.");
+        if ( executor != null ) {
+            try {
+                executor.execute(command);
+            } catch (RejectedExecutionException rx) {
+                //there could have been contention around the queue
+                if ( !( (TaskQueue) executor.getQueue()).force(command) ) throw new RejectedExecutionException();
+            }
+        } else throw new IllegalStateException("StandardThreadPool not started.");
     }
 
     public int getThreadPriority() {
@@ -171,10 +178,15 @@
         public void setParent(ThreadPoolExecutor tp) {
             parent = tp;
         }
+        
+        public boolean force(Runnable o) {
+            if ( parent.isShutdown() ) throw new RejectedExecutionException();
+            return super.offer(o); //forces the item onto the queue, to be used if the task is rejected
+        }
 
         public boolean offer(Runnable o) {
             if (parent != null && parent.getPoolSize() < parent.getMaximumPoolSize())
-                return false; //force creation of new threads
+                return false; //force creation of new threads by rejecting the task
             else
                 return super.offer(o);
         }



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