public class PrioritizedThreadPoolExecutor extends ThreadPoolExecutor
ThreadPoolExecutor.AbortPolicy, ThreadPoolExecutor.CallerRunsPolicy, ThreadPoolExecutor.DiscardOldestPolicy, ThreadPoolExecutor.DiscardPolicy
Constructor and Description |
---|
PrioritizedThreadPoolExecutor(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
PriorityBlockingQueue<Runnable> workQueue)
Creates a new
PrioritizedThreadPoolExecutor with the given initial
parameters and
default thread factory. |
PrioritizedThreadPoolExecutor(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
PriorityBlockingQueue<Runnable> workQueue,
RejectedExecutionHandler handler)
Creates a new
PrioritizedThreadPoolExecutor with the given initial
parameters and
default thread factory. |
Modifier and Type | Method and Description |
---|---|
protected <T> RunnableFuture<T> |
newTaskFor(Callable<T> inCallable)
Returns a
RunnableFuture for the given callable task. |
protected <T> RunnableFuture<T> |
newTaskFor(Callable<T> inCallable,
Priority inPriority)
Returns a
RunnableFuture for the given callable task. |
protected <T> RunnableFuture<T> |
newTaskFor(Runnable inRunnable,
T inValue)
Returns a
RunnableFuture for the given runnable and default
value. |
protected <T> RunnableFuture<T> |
newTaskFor(Runnable inRunnable,
T inValue,
Priority inPriority)
Returns a
RunnableFuture for the given runnable and default
value. |
<T> Future<T> |
submit(Callable<T> inTask) |
<T> Future<T> |
submit(Callable<T> inTask,
Priority inPriority) |
Future<?> |
submit(Runnable inTask) |
Future<?> |
submit(Runnable inTask,
Priority inPriority) |
<T> Future<T> |
submit(Runnable inTask,
T inResult) |
<T> Future<T> |
submit(Runnable task,
T result,
Priority inPriority) |
afterExecute, allowCoreThreadTimeOut, allowsCoreThreadTimeOut, awaitTermination, beforeExecute, execute, finalize, getActiveCount, getCompletedTaskCount, getCorePoolSize, getKeepAliveTime, getLargestPoolSize, getMaximumPoolSize, getPoolSize, getQueue, getRejectedExecutionHandler, getTaskCount, getThreadFactory, isShutdown, isTerminated, isTerminating, prestartAllCoreThreads, prestartCoreThread, purge, remove, setCorePoolSize, setKeepAliveTime, setMaximumPoolSize, setRejectedExecutionHandler, setThreadFactory, shutdown, shutdownNow, terminated, toString
invokeAll, invokeAll, invokeAny, invokeAny
public PrioritizedThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, PriorityBlockingQueue<Runnable> workQueue)
PrioritizedThreadPoolExecutor
with the given initial
parameters and
default thread factory.corePoolSize
- the number of threads to keep in the pool, even
if they are idle, unless allowCoreThreadTimeOut
is setmaximumPoolSize
- the maximum number of threads to allow in the
poolkeepAliveTime
- 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
argumentworkQueue
- the queue to use for holding tasks before they are
executed. This queue will hold only the Runnable
tasks submitted by the execute
method.IllegalArgumentException
- if one of the following holds:corePoolSize < 0
keepAliveTime < 0
maximumPoolSize <= 0
maximumPoolSize < corePoolSize
NullPointerException
- if workQueue
or handler
is nullpublic PrioritizedThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, PriorityBlockingQueue<Runnable> workQueue, RejectedExecutionHandler handler)
PrioritizedThreadPoolExecutor
with the given initial
parameters and
default thread factory.corePoolSize
- the number of threads to keep in the pool, even
if they are idle, unless allowCoreThreadTimeOut
is setmaximumPoolSize
- the maximum number of threads to allow in the
poolkeepAliveTime
- 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
argumentworkQueue
- 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 reachedIllegalArgumentException
- if one of the following holds:corePoolSize < 0
keepAliveTime < 0
maximumPoolSize <= 0
maximumPoolSize < corePoolSize
NullPointerException
- if workQueue
or handler
is nullpublic Future<?> submit(Runnable inTask)
submit
in interface ExecutorService
submit
in class AbstractExecutorService
public <T> Future<T> submit(Runnable inTask, T inResult)
submit
in interface ExecutorService
submit
in class AbstractExecutorService
public <T> Future<T> submit(Callable<T> inTask)
submit
in interface ExecutorService
submit
in class AbstractExecutorService
protected <T> RunnableFuture<T> newTaskFor(Runnable inRunnable, T inValue)
RunnableFuture
for the given runnable and default
value.newTaskFor
in class AbstractExecutorService
T
- the type of the given valueinRunnable
- the runnable task being wrappedinValue
- the default value for the returned futureRunnableFuture
which, when run, will run the
underlying runnable and which, as a Future
, will yield
the given value as its result and provide for cancellation of
the underlying taskprotected <T> RunnableFuture<T> newTaskFor(Runnable inRunnable, T inValue, Priority inPriority)
RunnableFuture
for the given runnable and default
value.T
- the type of the given valueinRunnable
- the runnable task being wrappedinValue
- the default value for the returned futureinPriority
- the job's priorityRunnableFuture
which, when run, will run the
underlying runnable and which, as a Future
, will yield
the given value as its result and provide for cancellation of
the underlying taskprotected <T> RunnableFuture<T> newTaskFor(Callable<T> inCallable)
RunnableFuture
for the given callable task.newTaskFor
in class AbstractExecutorService
T
- the type of the callable's resultinCallable
- the callable task being wrappedRunnableFuture
which, when run, will call the
underlying callable and which, as a Future
, will yield
the callable's result as its result and provide for
cancellation of the underlying taskprotected <T> RunnableFuture<T> newTaskFor(Callable<T> inCallable, Priority inPriority)
RunnableFuture
for the given callable task.T
- the type of the callable's resultinCallable
- the callable task being wrappedinPriority
- the job's priorityRunnableFuture
which, when run, will call the
underlying callable and which, as a Future
, will yield
the callable's result as its result and provide for
cancellation of the underlying task