Interface WorkerPool
- All Superinterfaces:
AutoCloseable,Executor,ExecutorService
- All Known Implementing Classes:
ForkJoinPoolWrapper,ManagedThreadPool
This interface exists primarily for backward compatibility with ForkJoinPool-based
implementations. ForkJoinPool uses work-stealing with internally distributed queues
that offer no API for external queue manipulation, making per-actor job cancellation
impossible. Replacing it with ManagedThreadPool (ThreadPoolExecutor +
LinkedBlockingDeque) enables direct queue access via queue.remove(), but
would break callers that reference ExecutorService directly.
By introducing this interface with no-op default methods, existing ForkJoinPool
wrappers continue to work unchanged. Only ManagedThreadPool overrides the
defaults and returns supportsCancellation() == true.
Callers should check supportsCancellation() before relying on
cancelJobsForActor(String).
- Since:
- 2.0.0
- Author:
- devteam@scivicslab.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault intcancelJobsForActor(String actorName) Cancels all pending (not yet started) jobs submitted for the given actor.default intgetPendingJobCountForActor(String actorName) Returns the number of pending (not yet started) jobs for the given actor.default booleanReturns whether this implementation supports per-actor job cancellation.Methods inherited from interface java.util.concurrent.ExecutorService
awaitTermination, close, invokeAll, invokeAll, invokeAny, invokeAny, isShutdown, isTerminated, shutdown, shutdownNow, submit, submit, submit
-
Method Details
-
cancelJobsForActor
Cancels all pending (not yet started) jobs submitted for the given actor. Jobs already running are not interrupted and will run to completion.The default implementation is a no-op for ForkJoinPool-based implementations, which cannot access their internal queues.
- Parameters:
actorName- the name of the actor whose pending jobs should be cancelled- Returns:
- the number of jobs removed from the queue; 0 if unsupported
-
getPendingJobCountForActor
Returns the number of pending (not yet started) jobs for the given actor.The default implementation returns 0 for ForkJoinPool-based implementations.
- Parameters:
actorName- the name of the actor- Returns:
- the number of pending jobs; 0 if unsupported
-
supportsCancellation
default boolean supportsCancellation()Returns whether this implementation supports per-actor job cancellation.Returns
falsefor ForkJoinPool-based implementations. ReturnstrueforManagedThreadPool.- Returns:
- true if
cancelJobsForActor(String)actually removes jobs
-