01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19:
20: package org.apache.synapse.util.concurrent;
21:
22: import org.apache.synapse.config.SynapseConfiguration;
23:
24: import java.util.concurrent.*;
25:
26: /**
27: * This is the executor service that will be returned by the env
28: */
29: public class SynapseThreadPool extends ThreadPoolExecutor {
30:
31: // default values
32: public static final int SYNAPSE_CORE_THREADS = 20;
33: public static final int SYNAPSE_MAX_THREADS = 100;
34: public static final int SYNAPSE_KEEP_ALIVE = 5;
35: public static final int SYNAPSE_THREAD_QLEN = 10;
36: public static final String SYNAPSE_THREAD_GROUP = "synapse-thread-group";
37: public static final String SYNAPSE_THREAD_ID_PREFIX = "SynapseWorker";
38:
39: // property keys
40: public static final String SYN_THREAD_CORE = "synapse.threads.core";
41: public static final String SYN_THREAD_MAX = "synapse.threads.max";
42: public static final String SYN_THREAD_ALIVE = "synapse.threads.keepalive";
43: public static final String SYN_THREAD_QLEN = "synapse.threads.qlen";
44: public static final String SYN_THREAD_GROUP = "synapse.threads.group";
45: public static final String SYN_THREAD_IDPREFIX = "synapse.threads.idprefix";
46:
47: /**
48: * Constructor for the Synapse thread poll
49: *
50: * @param corePoolSize - number of threads to keep in the pool, even if they are idle
51: * @param maximumPoolSize - the maximum number of threads to allow in the pool
52: * @param keepAliveTime - this is the maximum time that excess idle threads will wait
53: * for new tasks before terminating.
54: * @param unit - the time unit for the keepAliveTime argument.
55: * @param workQueue - the queue to use for holding tasks before they are executed.
56: */
57: public SynapseThreadPool(int corePoolSize, int maximumPoolSize,
58: long keepAliveTime, TimeUnit unit,
59: BlockingQueue<Runnable> workQueue) {
60: super (
61: corePoolSize,
62: maximumPoolSize,
63: keepAliveTime,
64: unit,
65: workQueue,
66: new SynapseThreadFactory(new ThreadGroup(
67: SYNAPSE_THREAD_GROUP), SYNAPSE_THREAD_ID_PREFIX));
68: }
69:
70: /**
71: * Default Constructor for the thread pool and will use all the values as default
72: */
73: public SynapseThreadPool() {
74: this (SYNAPSE_CORE_THREADS, SYNAPSE_MAX_THREADS,
75: SYNAPSE_KEEP_ALIVE, TimeUnit.SECONDS,
76: new LinkedBlockingQueue<Runnable>());
77: }
78:
79: /**
80: * Constructor for the SynapseThreadPool
81: *
82: * @param corePoolSize - number of threads to keep in the pool, even if they are idle
83: * @param maxPoolSize - the maximum number of threads to allow in the pool
84: * @param keepAliveTime - this is the maximum time that excess idle threads will wait
85: * for new tasks before terminating.
86: * @param qlen - Thread Blocking Queue length
87: * @param threadGroup - ThreadGroup name
88: * @param threadIdPrefix - Thread id prefix
89: */
90: public SynapseThreadPool(int corePoolSize, int maxPoolSize,
91: long keepAliveTime, int qlen, String threadGroup,
92: String threadIdPrefix) {
93: super (corePoolSize, maxPoolSize, keepAliveTime,
94: TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(
95: qlen), new SynapseThreadFactory(
96: new ThreadGroup(threadGroup), threadIdPrefix));
97: }
98: }
|