View | Details | Raw Unified | Return to bug 52996
Collapse All | Expand All

(-)java/org/apache/catalina/core/StandardThreadExecutor.java (-4 / +22 lines)
Lines 78-83 Link Here
78
     */
78
     */
79
    protected AtomicInteger submittedTasksCount;
79
    protected AtomicInteger submittedTasksCount;
80
    
80
    
81
    /**
82
     * The maximum number of elements that can queue up before we reject them
83
     */
84
    protected int maxQueueSize = Integer.MAX_VALUE;
85
81
    private LifecycleSupport lifecycle = new LifecycleSupport(this);
86
    private LifecycleSupport lifecycle = new LifecycleSupport(this);
82
    // ---------------------------------------------- Constructors
87
    // ---------------------------------------------- Constructors
83
    public StandardThreadExecutor() {
88
    public StandardThreadExecutor() {
Lines 89-95 Link Here
89
    // ---------------------------------------------- Public Methods
94
    // ---------------------------------------------- Public Methods
90
    public void start() throws LifecycleException {
95
    public void start() throws LifecycleException {
91
        lifecycle.fireLifecycleEvent(BEFORE_START_EVENT, null);
96
        lifecycle.fireLifecycleEvent(BEFORE_START_EVENT, null);
92
        TaskQueue taskqueue = new TaskQueue();
97
        TaskQueue taskqueue = new TaskQueue(maxQueueSize);
93
        TaskThreadFactory tf = new TaskThreadFactory(namePrefix);
98
        TaskThreadFactory tf = new TaskThreadFactory(namePrefix);
94
        lifecycle.fireLifecycleEvent(START_EVENT, null);
99
        lifecycle.fireLifecycleEvent(START_EVENT, null);
95
        executor = new ThreadPoolExecutor(getMinSpareThreads(), getMaxThreads(), maxIdleTime, TimeUnit.MILLISECONDS,taskqueue, tf) {
100
        executor = new ThreadPoolExecutor(getMinSpareThreads(), getMaxThreads(), maxIdleTime, TimeUnit.MILLISECONDS,taskqueue, tf) {
Lines 124-130 Link Here
124
                //there could have been contention around the queue
129
                //there could have been contention around the queue
125
                if ( !( (TaskQueue) executor.getQueue()).force(command) ) {
130
                if ( !( (TaskQueue) executor.getQueue()).force(command) ) {
126
                	submittedTasksCount.decrementAndGet();
131
                	submittedTasksCount.decrementAndGet();
127
                	throw new RejectedExecutionException();
132
                	throw new RejectedExecutionException("Work queue full.");
128
                }
133
                }
129
            }
134
            }
130
        } else throw new IllegalStateException("StandardThreadPool not started.");
135
        } else throw new IllegalStateException("StandardThreadPool not started.");
Lines 196-201 Link Here
196
        this.name = name;
201
        this.name = name;
197
    }
202
    }
198
    
203
    
204
    public void setMaxQueueSize(int size) {
205
        this.maxQueueSize = size;
206
    }
207
208
    public int getMaxQueueSize() {
209
        return maxQueueSize;
210
    }
211
199
    /**
212
    /**
200
     * Add a LifecycleEvent listener to this component.
213
     * Add a LifecycleEvent listener to this component.
201
     *
214
     *
Lines 257-264 Link Here
257
            super();
270
            super();
258
        }
271
        }
259
272
260
        public TaskQueue(int initialCapacity) {
273
        public TaskQueue(int capacity) {
261
            super(initialCapacity);
274
            super(capacity);
262
        }
275
        }
263
276
264
        public TaskQueue(Collection<? extends Runnable> c) {
277
        public TaskQueue(Collection<? extends Runnable> c) {
Lines 274-279 Link Here
274
            return super.offer(o); //forces the item onto the queue, to be used if the task is rejected
287
            return super.offer(o); //forces the item onto the queue, to be used if the task is rejected
275
        }
288
        }
276
289
290
        public boolean force(Runnable o, long timeout, TimeUnit unit) throws InterruptedException {
291
            if ( parent.isShutdown() ) throw new RejectedExecutionException("Executor not running, can't force a command into the queue");
292
            return super.offer(o,timeout,unit); //forces the item onto the queue, to be used if the task is rejected
293
        }
294
277
        public boolean offer(Runnable o) {
295
        public boolean offer(Runnable o) {
278
            //we can't do any checks
296
            //we can't do any checks
279
            if (parent==null) return super.offer(o);
297
            if (parent==null) return super.offer(o);

Return to bug 52996