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

(-)java/org/apache/catalina/core/StandardThreadExecutor.java (-4 / +46 lines)
Lines 33-52 Link Here
33
public class StandardThreadExecutor implements Executor {
33
public class StandardThreadExecutor implements Executor {
34
    
34
    
35
    // ---------------------------------------------- Properties
35
    // ---------------------------------------------- Properties
36
    /**
37
     * Default thread priority
38
     */
36
    protected int threadPriority = Thread.NORM_PRIORITY;
39
    protected int threadPriority = Thread.NORM_PRIORITY;
37
40
41
    /**
42
     * Run threads in daemon or non-daemon state
43
     */
38
    protected boolean daemon = true;
44
    protected boolean daemon = true;
39
    
45
    
46
    /**
47
     * Default name prefix for the thread name
48
     */
40
    protected String namePrefix = "tomcat-exec-";
49
    protected String namePrefix = "tomcat-exec-";
41
    
50
    
51
    /**
52
     * max number of threads
53
     */
42
    protected int maxThreads = 200;
54
    protected int maxThreads = 200;
43
    
55
    
56
    /**
57
     * min number of threads
58
     */
44
    protected int minSpareThreads = 25;
59
    protected int minSpareThreads = 25;
45
    
60
    
61
    /**
62
     * idle time in milliseconds
63
     */
46
    protected int maxIdleTime = 60000;
64
    protected int maxIdleTime = 60000;
47
    
65
    
66
    /**
67
     * The executor we use for this component
68
     */
48
    protected ThreadPoolExecutor executor = null;
69
    protected ThreadPoolExecutor executor = null;
49
    
70
    
71
    /**
72
     * the name of this thread pool
73
     */
50
    protected String name;
74
    protected String name;
51
    
75
    
52
    /**
76
    /**
Lines 54-59 Link Here
54
     */
78
     */
55
    protected AtomicInteger submittedTasksCount;
79
    protected AtomicInteger submittedTasksCount;
56
    
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
    
57
    private LifecycleSupport lifecycle = new LifecycleSupport(this);
86
    private LifecycleSupport lifecycle = new LifecycleSupport(this);
58
    // ---------------------------------------------- Constructors
87
    // ---------------------------------------------- Constructors
59
    public StandardThreadExecutor() {
88
    public StandardThreadExecutor() {
Lines 65-71 Link Here
65
    // ---------------------------------------------- Public Methods
94
    // ---------------------------------------------- Public Methods
66
    public void start() throws LifecycleException {
95
    public void start() throws LifecycleException {
67
        lifecycle.fireLifecycleEvent(BEFORE_START_EVENT, null);
96
        lifecycle.fireLifecycleEvent(BEFORE_START_EVENT, null);
68
        TaskQueue taskqueue = new TaskQueue();
97
        TaskQueue taskqueue = new TaskQueue(maxQueueSize);
69
        TaskThreadFactory tf = new TaskThreadFactory(namePrefix);
98
        TaskThreadFactory tf = new TaskThreadFactory(namePrefix);
70
        lifecycle.fireLifecycleEvent(START_EVENT, null);
99
        lifecycle.fireLifecycleEvent(START_EVENT, null);
71
        executor = new ThreadPoolExecutor(getMinSpareThreads(), getMaxThreads(), maxIdleTime, TimeUnit.MILLISECONDS,taskqueue, tf) {
100
        executor = new ThreadPoolExecutor(getMinSpareThreads(), getMaxThreads(), maxIdleTime, TimeUnit.MILLISECONDS,taskqueue, tf) {
Lines 100-106 Link Here
100
                //there could have been contention around the queue
129
                //there could have been contention around the queue
101
                if ( !( (TaskQueue) executor.getQueue()).force(command) ) {
130
                if ( !( (TaskQueue) executor.getQueue()).force(command) ) {
102
                	submittedTasksCount.decrementAndGet();
131
                	submittedTasksCount.decrementAndGet();
103
                	throw new RejectedExecutionException();
132
                	throw new RejectedExecutionException("Work queue full.");
104
                }
133
                }
105
            }
134
            }
106
        } else throw new IllegalStateException("StandardThreadPool not started.");
135
        } else throw new IllegalStateException("StandardThreadPool not started.");
Lines 172-177 Link Here
172
        this.name = name;
201
        this.name = name;
173
    }
202
    }
174
    
203
    
204
    public void setMaxQueueSize(int size) {
205
        this.maxQueueSize = size;
206
    }
207
    
208
    public int getMaxQueueSize() {
209
        return maxQueueSize;
210
    }
211
    
175
    /**
212
    /**
176
     * Add a LifecycleEvent listener to this component.
213
     * Add a LifecycleEvent listener to this component.
177
     *
214
     *
Lines 233-240 Link Here
233
            super();
270
            super();
234
        }
271
        }
235
272
236
        public TaskQueue(int initialCapacity) {
273
        public TaskQueue(int capacity) {
237
            super(initialCapacity);
274
            super(capacity);
238
        }
275
        }
239
276
240
        public TaskQueue(Collection<? extends Runnable> c) {
277
        public TaskQueue(Collection<? extends Runnable> c) {
Lines 250-255 Link Here
250
            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
251
        }
288
        }
252
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
253
        public boolean offer(Runnable o) {
295
        public boolean offer(Runnable o) {
254
            //we can't do any checks
296
            //we can't do any checks
255
            if (parent==null) return super.offer(o);
297
            if (parent==null) return super.offer(o);

Return to bug 52996