org.eclipse.jetty.util.thread
Class ExecutorThreadPool
java.lang.Object
org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.thread.ExecutorThreadPool
- All Implemented Interfaces:
- LifeCycle, ThreadPool
public class ExecutorThreadPool
- extends AbstractLifeCycle
- implements ThreadPool, LifeCycle
Jetty ThreadPool using java 5 ThreadPoolExecutor
This class wraps a ExecutorService as a ThreadPool and
LifeCycle interfaces so that it may be used by the Jetty org.eclipse.jetty.server.Server
| Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle |
addLifeCycleListener, doStart, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop, toString |
ExecutorThreadPool
public ExecutorThreadPool(ExecutorService executor)
ExecutorThreadPool
public ExecutorThreadPool()
- Wraps an
ThreadPoolExecutor.
Max pool size is 256, pool thread timeout after 60 seconds and
an unbounded LinkedBlockingQueue is used for the job queue;
ExecutorThreadPool
public ExecutorThreadPool(int queueSize)
- Wraps an
ThreadPoolExecutor.
Max pool size is 256, pool thread timeout after 60 seconds, and core pool size is 32 when queueSize >= 0.
- Parameters:
queueSize - can be -1 for using an unbounded LinkedBlockingQueue, 0 for using a
SynchronousQueue, greater than 0 for using a ArrayBlockingQueue of the given size.
ExecutorThreadPool
public ExecutorThreadPool(int corePoolSize,
int maximumPoolSize,
long keepAliveTime)
- Wraps an
ThreadPoolExecutor using
an unbounded LinkedBlockingQueue is used for the jobs queue;
- Parameters:
corePoolSize - must be equal to maximumPoolSizemaximumPoolSize - the maximum number of threads to allow in the poolkeepAliveTime - the max time a thread can remain idle, in milliseconds
ExecutorThreadPool
public ExecutorThreadPool(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit)
- Wraps an
ThreadPoolExecutor using
an unbounded LinkedBlockingQueue is used for the jobs queue.
- Parameters:
corePoolSize - must be equal to maximumPoolSizemaximumPoolSize - the maximum number of threads to allow in the poolkeepAliveTime - the max time a thread can remain idleunit - the unit for the keepAliveTime
ExecutorThreadPool
public ExecutorThreadPool(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
BlockingQueue<Runnable> workQueue)
- Wraps an
ThreadPoolExecutor
- Parameters:
corePoolSize - the number of threads to keep in the pool, even if they are idlemaximumPoolSize - the maximum number of threads to allow in the poolkeepAliveTime - the max time a thread can remain idleunit - the unit for the keepAliveTimeworkQueue - the queue to use for holding tasks before they are executed
dispatch
public boolean dispatch(Runnable job)
- Specified by:
dispatch in interface ThreadPool
getIdleThreads
public int getIdleThreads()
- Specified by:
getIdleThreads in interface ThreadPool
- Returns:
- The number of idle threads in the pool
getThreads
public int getThreads()
- Specified by:
getThreads in interface ThreadPool
- Returns:
- The total number of threads currently in the pool
isLowOnThreads
public boolean isLowOnThreads()
- Specified by:
isLowOnThreads in interface ThreadPool
- Returns:
- True if the pool is low on threads
join
public void join()
throws InterruptedException
- Description copied from interface:
ThreadPool
- Blocks until the thread pool is
stopped.
- Specified by:
join in interface ThreadPool
- Throws:
InterruptedException
doStop
protected void doStop()
throws Exception
- Overrides:
doStop in class AbstractLifeCycle
- Throws:
Exception
Copyright © 1995-2011 Mort Bay Consulting. All Rights Reserved.