Class ManagedScheduler
java.lang.Object
dev.ua.theroer.magicutils.platform.ManagedExecutor
dev.ua.theroer.magicutils.platform.ManagedScheduler
- All Implemented Interfaces:
AutoCloseable
A thin
AutoCloseable wrapper around a ScheduledExecutorService.
Extends ManagedExecutor with scheduling capabilities. Can be registered
with MagicRuntime.manage() for automatic shutdown when the runtime closes.
-
Method Summary
Modifier and TypeMethodDescriptionexecutor()Returns the underlying scheduled executor for direct use.Schedules a one-shot task.scheduleAtFixedRate(Runnable task, long delay, long period, TimeUnit unit) Schedules a task at a fixed rate.scheduleWithFixedDelay(Runnable task, long initialDelay, long delay, TimeUnit unit) Schedules a task with a fixed delay between completion and next start.Methods inherited from class ManagedExecutor
close, execute, isShutdown, runAsync, shutdown, shutdownNow, supplyAsync
-
Method Details
-
executor
Returns the underlying scheduled executor for direct use.- Overrides:
executorin classManagedExecutor- Returns:
- backing scheduled executor
-
scheduleAtFixedRate
public ScheduledFuture<?> scheduleAtFixedRate(Runnable task, long delay, long period, TimeUnit unit) Schedules a task at a fixed rate.- Parameters:
task- task to rundelay- initial delayperiod- period between runsunit- time unit- Returns:
- scheduled future handle
-
scheduleWithFixedDelay
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, long initialDelay, long delay, TimeUnit unit) Schedules a task with a fixed delay between completion and next start.- Parameters:
task- task to runinitialDelay- initial delaydelay- delay between runsunit- time unit- Returns:
- scheduled future handle
-
schedule
Schedules a one-shot task.- Parameters:
task- task to rundelay- delay before executionunit- time unit- Returns:
- scheduled future handle
-