Package com.scivicslab.pojoactor.core
Class ControllableWorkStealingPool
java.lang.Object
java.util.concurrent.AbstractExecutorService
java.util.concurrent.ThreadPoolExecutor
com.scivicslab.pojoactor.core.ControllableWorkStealingPool
- All Implemented Interfaces:
WorkerPool,AutoCloseable,Executor,ExecutorService
A controllable thread pool executor that supports actor-level job management.
Unlike ForkJoinPool, this implementation uses ThreadPoolExecutor with LinkedBlockingDeque,
allowing direct access to the queue for cancellation and priority execution.
Features:
- Track jobs per actor
- Cancel all jobs for a specific actor
- Submit urgent jobs to the front of the queue
- Query pending job count per actor
Note: This implementation does not provide work-stealing behavior like ForkJoinPool.
However, for POJO-actor's use case (independent CPU-bound tasks), the performance
difference is minimal, and the added control capabilities are more valuable.
- Since:
- 1.0.0
- Author:
- devteam@scivics-lab.com
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.concurrent.ThreadPoolExecutor
ThreadPoolExecutor.AbortPolicy, ThreadPoolExecutor.CallerRunsPolicy, ThreadPoolExecutor.DiscardOldestPolicy, ThreadPoolExecutor.DiscardPolicy -
Constructor Summary
ConstructorsConstructorDescriptionControllableWorkStealingPool(int parallelism) Creates a ControllableWorkStealingPool with the specified parallelism level. -
Method Summary
Modifier and TypeMethodDescriptionintcancelJobsForActor(String actorName) Cancels all pending jobs for a specific actor.intgetPendingJobCountForActor(String actorName) Gets the number of pending jobs for a specific actor.intGets the total number of actors currently tracked.voidsubmitForActor(String actorName, Runnable task) Submits a task associated with a specific actor.voidsubmitUrgentForActor(String actorName, Runnable task) Submits an urgent task to the front of the queue.booleanChecks if this worker pool supports job cancellation per actor.Methods inherited from class java.util.concurrent.ThreadPoolExecutor
afterExecute, allowCoreThreadTimeOut, allowsCoreThreadTimeOut, awaitTermination, beforeExecute, execute, finalize, getActiveCount, getCompletedTaskCount, getCorePoolSize, getKeepAliveTime, getLargestPoolSize, getMaximumPoolSize, getPoolSize, getQueue, getRejectedExecutionHandler, getTaskCount, getThreadFactory, isShutdown, isTerminated, isTerminating, prestartAllCoreThreads, prestartCoreThread, purge, remove, setCorePoolSize, setKeepAliveTime, setMaximumPoolSize, setRejectedExecutionHandler, setThreadFactory, shutdown, shutdownNow, terminated, toStringMethods inherited from class java.util.concurrent.AbstractExecutorService
invokeAll, invokeAll, invokeAny, invokeAny, newTaskFor, newTaskFor, submit, submit, submitMethods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.concurrent.ExecutorService
awaitTermination, close, invokeAll, invokeAll, invokeAny, invokeAny, isShutdown, isTerminated, shutdown, shutdownNow, submit, submit, submit
-
Constructor Details
-
ControllableWorkStealingPool
public ControllableWorkStealingPool(int parallelism) Creates a ControllableWorkStealingPool with the specified parallelism level.- Parameters:
parallelism- the number of threads in the pool
-
-
Method Details
-
submitForActor
Submits a task associated with a specific actor. The task is added to the end of the queue (normal priority).- Parameters:
actorName- the name of the actor submitting this tasktask- the task to execute
-
submitUrgentForActor
Submits an urgent task to the front of the queue. The task will be executed before other pending tasks.- Parameters:
actorName- the name of the actor submitting this tasktask- the urgent task to execute
-
supportsCancellation
public boolean supportsCancellation()Description copied from interface:WorkerPoolChecks if this worker pool supports job cancellation per actor.- Specified by:
supportsCancellationin interfaceWorkerPool- Returns:
- true if cancelJobsForActor() is supported
-
cancelJobsForActor
Cancels all pending jobs for a specific actor. Jobs that are already running will continue to completion. Only jobs that are still in the queue will be removed.- Specified by:
cancelJobsForActorin interfaceWorkerPool- Parameters:
actorName- the name of the actor whose jobs should be cancelled- Returns:
- the number of jobs that were cancelled
-
getPendingJobCountForActor
Gets the number of pending jobs for a specific actor. This includes jobs in the queue but not currently executing jobs.- Specified by:
getPendingJobCountForActorin interfaceWorkerPool- Parameters:
actorName- the name of the actor- Returns:
- the number of pending jobs
-
getTrackedActorCount
public int getTrackedActorCount()Gets the total number of actors currently tracked.- Returns:
- the number of actors with pending or running jobs
-