Package net.datenwerke.async
Interface DwAsyncPool
- All Known Implementing Classes:
DwAsyncPoolImpl
public interface DwAsyncPool
A thread pool allowing to run asynchronous tasks.
-
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.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.<T> Future<T> 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.
-
Method Details
-
submit
Submits 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.- Parameters:
task-- See Also:
-
submit
Submits a Runnable task for execution and returns a Future representing that task. The Future's get method will return null upon successful completion.- Parameters:
task-- See Also:
-
submit
Submits 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.- Parameters:
task-- See Also:
-
getActiveCount
int getActiveCount()Returns the approximate number of threads that are actively executing tasks.- Returns:
- the number of threads
- See Also:
-
getTaskCount
long getTaskCount()Returns 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.- Returns:
- the number of threads
- See Also:
-
getCompletedTaskCount
long getCompletedTaskCount()Returns 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.- Returns:
- the number of threads
- See Also:
-
getPoolSize
int getPoolSize()Returns the current number of threads in the pool.- Returns:
- the number of threads
- See Also:
-
getCorePoolSize
int getCorePoolSize()Returns the core number of threads.- Returns:
- the core number of threads
- See Also:
-
isShutdown
boolean isShutdown()Returns true if the pool has been shut down (orderly). -
isTerminated
boolean isTerminated()Returns true if the pool has been terminated -
awaitTermination
Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.- Parameters:
timeout-unit-- Throws:
InterruptedException- See Also:
-
shutdown
void shutdown()Initiates 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.- See Also:
-
shutdownNow
Attempts 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.- Returns:
- list of tasks that never commenced execution
- See Also:
-