public class NamingThreadPoolExecutor
extends java.util.concurrent.ThreadPoolExecutor
ThreadPoolExecutor
that allows to attach names to the threads it manages. These names
can come either from IRunnableNameProvider
s or ICallableNameProvider
s, or, if
their standard counterparts are submitted, a default name is used.java.util.concurrent.ThreadPoolExecutor.AbortPolicy, java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy, java.util.concurrent.ThreadPoolExecutor.DiscardOldestPolicy, java.util.concurrent.ThreadPoolExecutor.DiscardPolicy
Modifier and Type | Field and Description |
---|---|
static long |
DEFAULT_KEEP_ALIVE_TIME_MILLIS
The default time (in milli-seconds) to keep threads alive that are above the core pool size.
|
Constructor and Description |
---|
NamingThreadPoolExecutor(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
java.util.concurrent.TimeUnit unit,
java.util.concurrent.BlockingQueue<java.lang.Runnable> workQueue,
NamingThreadFactory threadFactory)
Creates a new NamingThreadPoolExecutor with the given initial parameters.
|
NamingThreadPoolExecutor(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
java.util.concurrent.TimeUnit unit,
java.util.concurrent.BlockingQueue<java.lang.Runnable> workQueue,
NamingThreadFactory threadFactory,
java.util.concurrent.RejectedExecutionHandler handler)
Creates a new NamingThreadPoolExecutor with the given initial parameters.
|
NamingThreadPoolExecutor(java.lang.String poolName)
Creates a new (caching) NamingThreadPoolExecutor with the given initial parameters.
|
NamingThreadPoolExecutor(java.lang.String poolName,
int workQueueSize)
Creates a new (caching) NamingThreadPoolExecutor with the given initial parameters.
|
NamingThreadPoolExecutor(java.lang.String poolName,
int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
java.util.concurrent.TimeUnit unit,
java.util.concurrent.BlockingQueue<java.lang.Runnable> workQueue)
Creates a new NamingThreadPoolExecutor with the given initial parameters.
|
NamingThreadPoolExecutor(java.lang.String poolName,
int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
java.util.concurrent.TimeUnit unit,
java.util.concurrent.BlockingQueue<java.lang.Runnable> workQueue,
java.util.concurrent.RejectedExecutionHandler handler)
Creates a new NamingThreadPoolExecutor with the given initial parameters.
|
Modifier and Type | Method and Description |
---|---|
NamingThreadPoolExecutor |
addPoolName(boolean addPoolName)
If addPoolName is
true , the threads will contain the pool name as the
first part of the thread names. |
protected void |
afterExecute(java.lang.Runnable r,
java.lang.Throwable t) |
protected void |
beforeExecute(java.lang.Thread t,
java.lang.Runnable r) |
NamingThreadPoolExecutor |
corePoolSize(int corePoolSize)
Same as
ThreadPoolExecutor.setCorePoolSize(int) , but returns the object itself for chaining. |
NamingThreadPoolExecutor |
daemonize()
Sets the thread factory of this pool executor to daemon creation mode.
|
NamingThreadFactory |
getThreadFactory() |
NamingThreadPoolExecutor |
keepAliveTime(long keepAliveTimeMillis)
Same as
ThreadPoolExecutor.setKeepAliveTime(long, TimeUnit) , but uses always
TimeUnit.MILLISECONDS and returns the object itself for chaining. |
NamingThreadPoolExecutor |
maximumPoolSize(int maximumPoolSize)
Same as
ThreadPoolExecutor.setMaximumPoolSize(int) , but returns the object itself for chaining. |
void |
setThreadFactory(NamingThreadFactory threadFactory)
Sets the thread factory of this pool executor.
|
void |
setThreadFactory(java.util.concurrent.ThreadFactory threadFactory)
Deprecated.
Use
setThreadFactory(NamingThreadFactory) instead! |
<T> java.util.concurrent.Future<T> |
submit(java.util.concurrent.Callable<T> task) |
java.util.concurrent.Future<?> |
submit(java.lang.Runnable task) |
<T> java.util.concurrent.Future<T> |
submit(java.lang.Runnable task,
T result) |
allowCoreThreadTimeOut, allowsCoreThreadTimeOut, awaitTermination, execute, finalize, getActiveCount, getCompletedTaskCount, getCorePoolSize, getKeepAliveTime, getLargestPoolSize, getMaximumPoolSize, getPoolSize, getQueue, getRejectedExecutionHandler, getTaskCount, isShutdown, isTerminated, isTerminating, prestartAllCoreThreads, prestartCoreThread, purge, remove, setCorePoolSize, setKeepAliveTime, setMaximumPoolSize, setRejectedExecutionHandler, shutdown, shutdownNow, terminated, toString
public static final long DEFAULT_KEEP_ALIVE_TIME_MILLIS
public NamingThreadPoolExecutor(java.lang.String poolName)
poolName
- the default name for new threadspublic NamingThreadPoolExecutor(java.lang.String poolName, int workQueueSize)
poolName
- The default name for new threads.workQueueSize
- The size of the work queue (0 for no queue).public NamingThreadPoolExecutor(java.lang.String poolName, int corePoolSize, int maximumPoolSize, long keepAliveTime, java.util.concurrent.TimeUnit unit, java.util.concurrent.BlockingQueue<java.lang.Runnable> workQueue, java.util.concurrent.RejectedExecutionHandler handler)
poolName
- the default name for new threadscorePoolSize
- the number of threads to keep in the pool, even if they are idle.maximumPoolSize
- the maximum number of threads to allow in the pool.keepAliveTime
- when the number of threads is greater than the core, this is the maximum
time that excess idle threads will wait for new tasks before terminating.unit
- the time unit for the keepAliveTime argument.workQueue
- the queue to use for holding tasks before they are executed. This queue will
hold only the Runnable tasks submitted by the execute method.handler
- the handler to use when execution is blocked because the thread bounds and
queue capacities are reached.java.lang.IllegalArgumentException
- if corePoolSize, or keepAliveTime less than zero, or if
maximumPoolSize less than or equal to zero, or if corePoolSize greater than
maximumPoolSize.java.lang.NullPointerException
- if workQueue or threadFactory or
handler are null.public NamingThreadPoolExecutor(java.lang.String poolName, int corePoolSize, int maximumPoolSize, long keepAliveTime, java.util.concurrent.TimeUnit unit, java.util.concurrent.BlockingQueue<java.lang.Runnable> workQueue)
poolName
- the default name for new threadscorePoolSize
- the number of threads to keep in the pool, even if they are idle.maximumPoolSize
- the maximum number of threads to allow in the pool.keepAliveTime
- when the number of threads is greater than the core, this is the maximum
time that excess idle threads will wait for new tasks before terminating.unit
- the time unit for the keepAliveTime argument.workQueue
- the queue to use for holding tasks before they are executed. This queue will
hold only the Runnable tasks submitted by the execute method.java.lang.IllegalArgumentException
- if corePoolSize, or keepAliveTime less than zero, or if
maximumPoolSize less than or equal to zero, or if corePoolSize greater than
maximumPoolSize.java.lang.NullPointerException
- if workQueue or threadFactory are null.public NamingThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, java.util.concurrent.TimeUnit unit, java.util.concurrent.BlockingQueue<java.lang.Runnable> workQueue, NamingThreadFactory threadFactory, java.util.concurrent.RejectedExecutionHandler handler)
corePoolSize
- the number of threads to keep in the pool, even if they are idle.maximumPoolSize
- the maximum number of threads to allow in the pool.keepAliveTime
- when the number of threads is greater than the core, this is the maximum
time that excess idle threads will wait for new tasks before terminating.unit
- the time unit for the keepAliveTime argument.workQueue
- the queue to use for holding tasks before they are executed. This queue will
hold only the Runnable tasks submitted by the execute method.threadFactory
- the factory to use when the executor creates a new thread.handler
- the handler to use when execution is blocked because the thread bounds and
queue capacities are reached.java.lang.IllegalArgumentException
- if corePoolSize, or keepAliveTime less than zero, or if
maximumPoolSize less than or equal to zero, or if corePoolSize greater than
maximumPoolSize.java.lang.NullPointerException
- if workQueue or threadFactory or
handler are null.public NamingThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, java.util.concurrent.TimeUnit unit, java.util.concurrent.BlockingQueue<java.lang.Runnable> workQueue, NamingThreadFactory threadFactory)
corePoolSize
- the number of threads to keep in the pool, even if they are idle.maximumPoolSize
- the maximum number of threads to allow in the pool.keepAliveTime
- when the number of threads is greater than the core, this is the maximum
time that excess idle threads will wait for new tasks before terminating.unit
- the time unit for the keepAliveTime argument.workQueue
- the queue to use for holding tasks before they are executed. This queue will
hold only the Runnable tasks submitted by the execute method.threadFactory
- the factory to use when the executor creates a new thread.java.lang.IllegalArgumentException
- if corePoolSize, or keepAliveTime less than zero, or if
maximumPoolSize less than or equal to zero, or if corePoolSize greater than
maximumPoolSize.java.lang.NullPointerException
- if workQueue or threadFactory are null.public NamingThreadPoolExecutor daemonize()
This method is supposed to be used in chaining mode, i.e.
final ExecutorService executor = new NamingThreadPoolExecutor("name").daemonize();
public NamingThreadPoolExecutor corePoolSize(int corePoolSize)
ThreadPoolExecutor.setCorePoolSize(int)
, but returns the object itself for chaining.public NamingThreadPoolExecutor maximumPoolSize(int maximumPoolSize)
ThreadPoolExecutor.setMaximumPoolSize(int)
, but returns the object itself for chaining.public NamingThreadPoolExecutor keepAliveTime(long keepAliveTimeMillis)
ThreadPoolExecutor.setKeepAliveTime(long, TimeUnit)
, but uses always
TimeUnit.MILLISECONDS
and returns the object itself for chaining.public NamingThreadPoolExecutor addPoolName(boolean addPoolName)
true
, the threads will contain the pool name as the
first part of the thread names.public NamingThreadFactory getThreadFactory()
getThreadFactory
in class java.util.concurrent.ThreadPoolExecutor
public void setThreadFactory(NamingThreadFactory threadFactory)
@Deprecated public void setThreadFactory(java.util.concurrent.ThreadFactory threadFactory)
setThreadFactory(NamingThreadFactory)
instead!setThreadFactory
in class java.util.concurrent.ThreadPoolExecutor
protected void beforeExecute(java.lang.Thread t, java.lang.Runnable r)
beforeExecute
in class java.util.concurrent.ThreadPoolExecutor
protected void afterExecute(java.lang.Runnable r, java.lang.Throwable t)
afterExecute
in class java.util.concurrent.ThreadPoolExecutor
public java.util.concurrent.Future<?> submit(java.lang.Runnable task)
submit
in interface java.util.concurrent.ExecutorService
submit
in class java.util.concurrent.AbstractExecutorService
public <T> java.util.concurrent.Future<T> submit(java.lang.Runnable task, T result)
submit
in interface java.util.concurrent.ExecutorService
submit
in class java.util.concurrent.AbstractExecutorService
public <T> java.util.concurrent.Future<T> submit(java.util.concurrent.Callable<T> task)
submit
in interface java.util.concurrent.ExecutorService
submit
in class java.util.concurrent.AbstractExecutorService