Package net.datenwerke.async
Class DwAsyncPoolImpl
java.lang.Object
net.datenwerke.async.DwAsyncPoolImpl
- All Implemented Interfaces:
DwAsyncPool
Default implementation of
DwAsyncPool-
Constructor Summary
ConstructorsConstructorDescriptionDwAsyncPoolImpl(String threadLabel) Creates a new pool with the given label.DwAsyncPoolImpl(DwThreadPoolExecutor executorService) Creates a new thread pool from the given executor. -
Method Summary
Modifier and TypeMethodDescriptionbooleanawaitTermination(long timeout, TimeUnit unit) Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.intReturns the approximate number of threads that are actively executing tasks.longReturns the approximate total number of tasks that have completed execution.intReturns the core number of threads.Returns the underlyingExecutorServiceobject.intReturns the current number of threads in the pool.longReturns the approximate total number of tasks that have ever been scheduled for execution.booleanReturns true if the pool has been shut down (orderly).booleanReturns true if the pool has been terminatedvoidshutdown()Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted.Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution.Future<?> Submits a Runnable task for execution and returns a Future representing that task.<T> Future<T> Submits a Runnable task for execution and returns a Future representing that task.<T> Future<T> Submits a value-returning task for execution and returns a Future representing the pending results of the task.
-
Constructor Details
-
DwAsyncPoolImpl
Creates a new pool with the given label. The pool will be created as aThreadPoolFactory.newCachedThreadPool(String).- Parameters:
threadLabel-- See Also:
-
DwAsyncPoolImpl
Creates a new thread pool from the given executor.- Parameters:
executorService-
-
-
Method Details
-
submit
Description copied from interface:DwAsyncPoolSubmits a value-returning task for execution and returns a Future representing the pending results of the task. The Future's get method will return the task's result upon successful completion.- Specified by:
submitin interfaceDwAsyncPool- Parameters:
task-- See Also:
-
submit
Description copied from interface:DwAsyncPoolSubmits a Runnable task for execution and returns a Future representing that task. The Future's get method will return null upon successful completion.- Specified by:
submitin interfaceDwAsyncPool- Parameters:
task-- See Also:
-
submit
Description copied from interface:DwAsyncPoolSubmits a Runnable task for execution and returns a Future representing that task. The Future's get method will return the given result upon successful completion.- Specified by:
submitin interfaceDwAsyncPool- Parameters:
task-- See Also:
-
awaitTermination
Description copied from interface:DwAsyncPoolBlocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.- Specified by:
awaitTerminationin interfaceDwAsyncPool- Parameters:
timeout-unit-- Throws:
InterruptedException- See Also:
-
getExecutorService
Returns the underlyingExecutorServiceobject. -
getActiveCount
public int getActiveCount()Description copied from interface:DwAsyncPoolReturns the approximate number of threads that are actively executing tasks.- Specified by:
getActiveCountin interfaceDwAsyncPool- Returns:
- the number of threads
- See Also:
-
getPoolSize
public int getPoolSize()Description copied from interface:DwAsyncPoolReturns the current number of threads in the pool.- Specified by:
getPoolSizein interfaceDwAsyncPool- Returns:
- the number of threads
- See Also:
-
getCorePoolSize
public int getCorePoolSize()Description copied from interface:DwAsyncPoolReturns the core number of threads.- Specified by:
getCorePoolSizein interfaceDwAsyncPool- Returns:
- the core number of threads
- See Also:
-
getTaskCount
public long getTaskCount()Description copied from interface:DwAsyncPoolReturns the approximate total number of tasks that have ever been scheduled for execution. Because the states of tasks and threads may change dynamically during computation, the returned value is only an approximation.- Specified by:
getTaskCountin interfaceDwAsyncPool- Returns:
- the number of threads
- See Also:
-
getCompletedTaskCount
public long getCompletedTaskCount()Description copied from interface:DwAsyncPoolReturns the approximate total number of tasks that have completed execution. Because the states of tasks and threads may change dynamically during computation, the returned value is only an approximation, but one that does not ever decrease across successive calls.- Specified by:
getCompletedTaskCountin interfaceDwAsyncPool- Returns:
- the number of threads
- See Also:
-
isShutdown
public boolean isShutdown()Description copied from interface:DwAsyncPoolReturns true if the pool has been shut down (orderly).- Specified by:
isShutdownin interfaceDwAsyncPool
-
isTerminated
public boolean isTerminated()Description copied from interface:DwAsyncPoolReturns true if the pool has been terminated- Specified by:
isTerminatedin interfaceDwAsyncPool
-
shutdown
public void shutdown()Description copied from interface:DwAsyncPoolInitiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted. Invocation has no additional effect if already shut down.This method does not wait for previously submitted tasks to complete execution. Use
awaitTerminationto do that.- Specified by:
shutdownin interfaceDwAsyncPool- See Also:
-
shutdownNow
Description copied from interface:DwAsyncPoolAttempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution.This method does not wait for actively executing tasks to terminate. Use
awaitTerminationto do that.There are no guarantees beyond best-effort attempts to stop processing actively executing tasks. For example, typical implementations will cancel via
Thread.interrupt(), so any task that fails to respond to interrupts may never terminate.- Specified by:
shutdownNowin interfaceDwAsyncPool- Returns:
- list of tasks that never commenced execution
- See Also:
-