Package org.threadly.concurrent.wrapper
Class SchedulerExecutorDelegator
- java.lang.Object
-
- org.threadly.concurrent.AbstractSubmitterExecutor
-
- org.threadly.concurrent.AbstractSubmitterScheduler
-
- org.threadly.concurrent.wrapper.SchedulerExecutorDelegator
-
- All Implemented Interfaces:
java.util.concurrent.Executor
,SubmitterExecutor
,SubmitterScheduler
public class SchedulerExecutorDelegator extends AbstractSubmitterScheduler
Class which takes in both an executor and a scheduler. Delegating executions to the executor when possible, and otherwise submitting to the provided scheduler. This can be used to provide different behavior/implementations between scheduled and executed tasks (for example you could useDefaultPriorityWrapper
to have a different default priority for scheduled tasks vs executed).- Since:
- 4.7.0
-
-
Constructor Summary
Constructors Constructor Description SchedulerExecutorDelegator(java.util.concurrent.Executor parentExecutor, SubmitterScheduler parentScheduler)
Constructs a new delegator with the provided pools to defer executions to.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
scheduleAtFixedRate(java.lang.Runnable task, long initialDelay, long period)
Schedule a fixed rate recurring task to run.void
scheduleWithFixedDelay(java.lang.Runnable task, long initialDelay, long recurringDelay)
Schedule a fixed delay recurring task to run.-
Methods inherited from class org.threadly.concurrent.AbstractSubmitterScheduler
schedule, submitScheduled, submitScheduled
-
Methods inherited from class org.threadly.concurrent.AbstractSubmitterExecutor
execute, submit, submit
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.threadly.concurrent.SubmitterExecutor
submit, submit, submit
-
Methods inherited from interface org.threadly.concurrent.SubmitterScheduler
submitScheduled
-
-
-
-
Constructor Detail
-
SchedulerExecutorDelegator
public SchedulerExecutorDelegator(java.util.concurrent.Executor parentExecutor, SubmitterScheduler parentScheduler)
Constructs a new delegator with the provided pools to defer executions to.- Parameters:
parentExecutor
- Executor to use when ever possibleparentScheduler
- Scheduler to use when executions need to be delayed
-
-
Method Detail
-
scheduleWithFixedDelay
public void scheduleWithFixedDelay(java.lang.Runnable task, long initialDelay, long recurringDelay)
Description copied from interface:SubmitterScheduler
Schedule a fixed delay recurring task to run. The recurring delay time will be from the point where execution has finished. So the execution frequency is therecurringDelay + runtime
for the provided task.Unlike
ScheduledExecutorService
if the task throws an exception, subsequent executions are NOT suppressed or prevented. So if the task throws an exception on every run, the task will continue to be executed at the provided recurring delay (possibly throwing an exception on each execution).- Parameters:
task
- runnable to be executedinitialDelay
- delay in milliseconds until first runrecurringDelay
- delay in milliseconds for running task after last finish
-
scheduleAtFixedRate
public void scheduleAtFixedRate(java.lang.Runnable task, long initialDelay, long period)
Description copied from interface:SubmitterScheduler
Schedule a fixed rate recurring task to run. The recurring delay will be the same, regardless of how long task execution takes. A given runnable will not run concurrently (unless it is submitted to the scheduler multiple times). Instead of execution takes longer than the period, the next run will occur immediately (given thread availability in the pool).Unlike
ScheduledExecutorService
if the task throws an exception, subsequent executions are NOT suppressed or prevented. So if the task throws an exception on every run, the task will continue to be executed at the provided recurring delay (possibly throwing an exception on each execution).- Parameters:
task
- runnable to be executedinitialDelay
- delay in milliseconds until first runperiod
- amount of time in milliseconds between the start of recurring executions
-
-