Package com.dua3.utility.concurrent
Class TaskProcessorAsync
java.lang.Object
com.dua3.utility.concurrent.TaskProcessorBase
com.dua3.utility.concurrent.TaskProcessorAsync
- All Implemented Interfaces:
TaskProcessor
TaskProcessor implementation where tasks are executed asynchronous using an ExecutorService.
When an instance is created, the number of maximum parallel tasks can be passed in.
-
Nested Class Summary
Nested classes/interfaces inherited from class com.dua3.utility.concurrent.TaskProcessorBase
TaskProcessorBase.State, TaskProcessorBase.Stats -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidShutdown and abort all submitted tasks.<T> CompletableFuture<T> Submit a task that that returns a result.booleanwaitForCompletion(long timeout, TimeUnit timeUnit) Wait until all submitted tasks have completed or a timeout occurs.Methods inherited from class com.dua3.utility.concurrent.TaskProcessorBase
addListener, ensureClosed, ensureOpen, getName, getState, getStats, isCompleted, isShutdown, newThreadFactory, nextId, registerId, registerParty, removeListener, shutdown, submit, terminate, unregisterId, unregisterPartyMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.dua3.utility.concurrent.TaskProcessor
submitFuture
-
Constructor Details
-
TaskProcessorAsync
Constructor.- Parameters:
name- this processor's namemaxThreads- maximal number of tasks that are executed parallel
-
-
Method Details
-
shutdownAndAbort
public void shutdownAndAbort()Description copied from interface:TaskProcessorShutdown and abort all submitted tasks.- Specified by:
shutdownAndAbortin interfaceTaskProcessor- Overrides:
shutdownAndAbortin classTaskProcessorBase
-
waitForCompletion
Description copied from interface:TaskProcessorWait until all submitted tasks have completed or a timeout occurs.- Specified by:
waitForCompletionin interfaceTaskProcessor- Overrides:
waitForCompletionin classTaskProcessorBase- Parameters:
timeout- the timeout valuetimeUnit- the unit to apply to the timeout value- Returns:
- true, if all tasks have completed, otherwise false (timeout)
-
submit
Description copied from interface:TaskProcessorSubmit a task that that returns a result.- Type Parameters:
T- the task result type- Parameters:
task- the task to execute- Returns:
- a
CompletableFuturefor the task
-