Class ThreadPool
java.lang.Object
java.util.concurrent.AbstractExecutorService
java.util.concurrent.ThreadPoolExecutor
org.eclipse.net4j.util.concurrent.ThreadPool
- All Implemented Interfaces:
AutoCloseable, Executor, ExecutorService, RejectedExecutionHandler
- Since:
- 3.6
- Author:
- Eike Stepper
-
Nested Class Summary
Nested classes/interfaces inherited from class ThreadPoolExecutor
ThreadPoolExecutor.AbortPolicy, ThreadPoolExecutor.CallerRunsPolicy, ThreadPoolExecutor.DiscardOldestPolicy, ThreadPoolExecutor.DiscardPolicy -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final longstatic final intstatic final String -
Constructor Summary
ConstructorsConstructorDescriptionThreadPool(int corePoolSize, int maximumPoolSize, long keepAliveSeconds, ThreadFactory threadFactory) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidafterExecute(Runnable task, Throwable ex) protected voidbeforeExecute(Thread worker, Runnable task) static ThreadPoolcreate()static ThreadPoolstatic ThreadPoolvoidSubmits a task through the executor's normal worker creation and queueing sequence.getQueue()Returns a live view of this executor's task queue.protected voidvoidrejectedExecution(Runnable task, ThreadPoolExecutor executor) Handles a task that the executor could not assign to a worker.voidvoidshutdown()Initiates an orderly shutdown.Attempts to stop active tasks and removes waiting tasks.protected voidMethods inherited from class ThreadPoolExecutor
allowCoreThreadTimeOut, allowsCoreThreadTimeOut, awaitTermination, finalize, getActiveCount, getCompletedTaskCount, getCorePoolSize, getKeepAliveTime, getLargestPoolSize, getMaximumPoolSize, getPoolSize, getTaskCount, getThreadFactory, isShutdown, isTerminated, isTerminating, prestartAllCoreThreads, prestartCoreThread, purge, remove, setCorePoolSize, setKeepAliveTime, setMaximumPoolSize, setThreadFactory, toStringMethods inherited from class AbstractExecutorService
invokeAll, invokeAll, invokeAny, invokeAny, newTaskFor, newTaskFor, submit, submit, submitMethods inherited from class Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface ExecutorService
close
-
Field Details
-
DEFAULT_THREAD_GROUP_NAME
- See Also:
-
DEFAULT_CORE_POOL_SIZE
public static final int DEFAULT_CORE_POOL_SIZE- See Also:
-
DEFAULT_MAXIMUM_POOL_SIZE
public static final int DEFAULT_MAXIMUM_POOL_SIZE -
DEFAULT_KEEP_ALIVE_SECONDS
public static final long DEFAULT_KEEP_ALIVE_SECONDS- See Also:
-
-
Constructor Details
-
ThreadPool
public ThreadPool(int corePoolSize, int maximumPoolSize, long keepAliveSeconds, ThreadFactory threadFactory)
-
-
Method Details
-
setRejectedExecutionHandler
- Overrides:
setRejectedExecutionHandlerin classThreadPoolExecutor
-
getRejectedExecutionHandler
- Overrides:
getRejectedExecutionHandlerin classThreadPoolExecutor
-
getQueue
Returns a live view of this executor's task queue. Queue operations have the same blocking and ordering behavior as the underlying queue, and removals through this view are reflected in the pool's pending-task accounting.- Overrides:
getQueuein classThreadPoolExecutor- Returns:
- the live task-queue view
-
rejectedExecution
Handles a task that the executor could not assign to a worker. The task is retained in the work queue only while the executor is running and either has reached its maximum size or has an idle worker; otherwise the configured user handler is invoked, or the task is rejected when no user handler is configured.- Specified by:
rejectedExecutionin interfaceRejectedExecutionHandler- Parameters:
task- the task that could not be assigned to a workerexecutor- the executor that rejected the task
-
execute
Submits a task through the executor's normal worker creation and queueing sequence.- Specified by:
executein interfaceExecutor- Overrides:
executein classThreadPoolExecutor- Parameters:
command- the task to execute- Throws:
RejectedExecutionException- if the task cannot be accepted and the configured rejection handler rejects itNullPointerException- if the task isnull
-
beforeExecute
- Overrides:
beforeExecutein classThreadPoolExecutor
-
afterExecute
- Overrides:
afterExecutein classThreadPoolExecutor
-
shutdown
public void shutdown()Initiates an orderly shutdown. Task admission and the shutdown transition share a lock so a concurrent task is either admitted before shutdown or rejected after shutdown begins.- Specified by:
shutdownin interfaceExecutorService- Overrides:
shutdownin classThreadPoolExecutor
-
shutdownNow
Attempts to stop active tasks and removes waiting tasks. Queue reservations for the returned waiting tasks are released before this method returns.- Specified by:
shutdownNowin interfaceExecutorService- Overrides:
shutdownNowin classThreadPoolExecutor- Returns:
- the tasks that were waiting to execute
-
terminated
protected void terminated()- Overrides:
terminatedin classThreadPoolExecutor
-
potentialDeadlockDetected
protected void potentialDeadlockDetected()- Since:
- 3.9
-
create
-
create
-
create
public static ThreadPool create(String threadGroupName, int corePoolSize, int maximumPoolSize, long keepAliveSeconds)
-