--- java/org/apache/catalina/core/StandardThreadExecutor.java (revision 1348086) +++ java/org/apache/catalina/core/StandardThreadExecutor.java (working copy) @@ -78,6 +78,11 @@ */ protected AtomicInteger submittedTasksCount; + /** + * The maximum number of elements that can queue up before we reject them + */ + protected int maxQueueSize = Integer.MAX_VALUE; + private LifecycleSupport lifecycle = new LifecycleSupport(this); // ---------------------------------------------- Constructors public StandardThreadExecutor() { @@ -89,7 +94,7 @@ // ---------------------------------------------- Public Methods public void start() throws LifecycleException { lifecycle.fireLifecycleEvent(BEFORE_START_EVENT, null); - TaskQueue taskqueue = new TaskQueue(); + TaskQueue taskqueue = new TaskQueue(maxQueueSize); TaskThreadFactory tf = new TaskThreadFactory(namePrefix); lifecycle.fireLifecycleEvent(START_EVENT, null); executor = new ThreadPoolExecutor(getMinSpareThreads(), getMaxThreads(), maxIdleTime, TimeUnit.MILLISECONDS,taskqueue, tf) { @@ -124,7 +129,7 @@ //there could have been contention around the queue if ( !( (TaskQueue) executor.getQueue()).force(command) ) { submittedTasksCount.decrementAndGet(); - throw new RejectedExecutionException(); + throw new RejectedExecutionException("Work queue full."); } } } else throw new IllegalStateException("StandardThreadPool not started."); @@ -196,6 +201,14 @@ this.name = name; } + public void setMaxQueueSize(int size) { + this.maxQueueSize = size; + } + + public int getMaxQueueSize() { + return maxQueueSize; + } + /** * Add a LifecycleEvent listener to this component. * @@ -257,8 +270,8 @@ super(); } - public TaskQueue(int initialCapacity) { - super(initialCapacity); + public TaskQueue(int capacity) { + super(capacity); } public TaskQueue(Collection c) { @@ -274,6 +287,11 @@ return super.offer(o); //forces the item onto the queue, to be used if the task is rejected } + public boolean force(Runnable o, long timeout, TimeUnit unit) throws InterruptedException { + if ( parent.isShutdown() ) throw new RejectedExecutionException("Executor not running, can't force a command into the queue"); + return super.offer(o,timeout,unit); //forces the item onto the queue, to be used if the task is rejected + } + public boolean offer(Runnable o) { //we can't do any checks if (parent==null) return super.offer(o);