import org.apache.catalina.LifecycleException;\r
import org.apache.catalina.LifecycleListener;\r
import org.apache.catalina.util.LifecycleSupport;\r
+import java.util.concurrent.RejectedExecutionException;\r
\r
public class StandardThreadExecutor implements Executor {\r
\r
}\r
\r
public void execute(Runnable command) {\r
- if ( executor != null ) executor.execute(command);\r
- else throw new IllegalStateException("StandardThreadPool not started.");\r
+ if ( executor != null ) {\r
+ try {\r
+ executor.execute(command);\r
+ } catch (RejectedExecutionException rx) {\r
+ //there could have been contention around the queue\r
+ if ( !( (TaskQueue) executor.getQueue()).force(command) ) throw new RejectedExecutionException();\r
+ }\r
+ } else throw new IllegalStateException("StandardThreadPool not started.");\r
}\r
\r
public int getThreadPriority() {\r
public void setParent(ThreadPoolExecutor tp) {\r
parent = tp;\r
}\r
+ \r
+ public boolean force(Runnable o) {\r
+ if ( parent.isShutdown() ) throw new RejectedExecutionException();\r
+ return super.offer(o); //forces the item onto the queue, to be used if the task is rejected\r
+ }\r
\r
public boolean offer(Runnable o) {\r
if (parent != null && parent.getPoolSize() < parent.getMaximumPoolSize())\r
- return false; //force creation of new threads\r
+ return false; //force creation of new threads by rejecting the task\r
else\r
return super.offer(o);\r
}\r