Interface BucketedExecutor<T extends Serializable>
- Type Parameters:
T
- the task type
public interface BucketedExecutor<T extends Serializable>
Executor that groups submitted tasks in 'buckets' and asynchronously processes these buckets of tasks on worker
threads. At
construction time
, a
BucketedExecutorSettings
is provided that defines the maximum concurrency level, the task bucketing logic
and the BucketProcessor
that's called for processing buckets of tasks.-
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a task to be processed and schedule theBucketProcessor
to process the task's bucket with adelay
.void
shutdown()
Shuts down the executor and releases all resources acquired by the executor.void
Submit a task for processing and schedule theBucketProcessor
to process the task's bucket immediately.
-
Method Details
-
schedule
Add a task to be processed and schedule theBucketProcessor
to process the task's bucket with adelay
. The task may still be processed earlier if a prior task for the same bucket has been scheduled to run before the scheduled time.- Parameters:
task
- the task to submitdelay
- the processing delaytimeUnit
- the delay's timeUnit
-
shutdown
void shutdown()Shuts down the executor and releases all resources acquired by the executor. This shuts down the executor on the current node only. In a cluster, the corresponding executors will keep processing tasks until they're shut down.Note: All plugins which
request
a bucketed executor must shut it down when the plugin is disabled. Failing to do so will leave behind orphaned instances. On plugin upgrade this can be particularly problematic given the fact that when the new version of the plugin requests an executor it will be provided with the old stale instance which may trigger unexpected behavior, likeClassCastException
s caused byClassLoader
mismatches. This behaviour will continue until the next time the system restarts (in a clustered environment this means every node). -
submit
Submit a task for processing and schedule theBucketProcessor
to process the task's bucket immediately. This is equivalent to callingschedule(Serializable, long, TimeUnit)
with adelay
of0
.- Parameters:
task
- the task to submit
-