Package com.glitchybyte.glib.concurrent
Class GTaskSchedulerService
java.lang.Object
com.glitchybyte.glib.concurrent.GTaskExecutorService<ScheduledExecutorService>
com.glitchybyte.glib.concurrent.GTaskSchedulerService
- All Implemented Interfaces:
GTaskScheduler,AutoCloseable,Executor
public final class GTaskSchedulerService
extends GTaskExecutorService<ScheduledExecutorService>
implements GTaskScheduler
A scheduler utility on top of
ScheduledExecutorService.
This class standardizes the interface to use Duration for timings.
-
Field Summary
Fields inherited from class com.glitchybyte.glib.concurrent.GTaskExecutorService
runner -
Constructor Summary
ConstructorsConstructorDescriptionCreates a task scheduler with a single worker thread.GTaskSchedulerService(Integer threadCount) Creates a task scheduler with a fixed thread pool.Creates a task scheduler with the givenScheduledExecutorService. -
Method Summary
Modifier and TypeMethodDescriptionSchedules a one-shot task.scheduleAtFixedRate(Duration initialDelay, Duration period, Runnable runnable) Schedules a task to run at a fixed delay.scheduleWithFixedDelay(Duration initialDelay, Duration delay, Runnable runnable) Schedules a task at a delay after each run.Methods inherited from class com.glitchybyte.glib.concurrent.GTaskExecutorService
close, createTaskWrapper, execute
-
Constructor Details
-
GTaskSchedulerService
public GTaskSchedulerService()Creates a task scheduler with a single worker thread. -
GTaskSchedulerService
Creates a task scheduler with a fixed thread pool.- Parameters:
threadCount- Thread count for this scheduler.
-
GTaskSchedulerService
Creates a task scheduler with the givenScheduledExecutorService.This scheduler owns the given
ScheduledExecutorServiceand will shut it down and close it when the scheduler is closed.- Parameters:
runner-ScheduledExecutorServiceto use as scheduler.
-
-
Method Details
-
schedule
Description copied from interface:GTaskSchedulerSchedules a one-shot task.- Specified by:
schedulein interfaceGTaskScheduler- Parameters:
delay- Delay before task execution.runnable- Task to schedule.- Returns:
- A
GCancelableto cancel the task.
-
scheduleAtFixedRate
Description copied from interface:GTaskSchedulerSchedules a task to run at a fixed delay.- Specified by:
scheduleAtFixedRatein interfaceGTaskScheduler- Parameters:
initialDelay- Delay before task execution.period- Cadence at which tasks run.runnable- Task to schedule.- Returns:
- A
GCancelableto cancel the task.
-
scheduleWithFixedDelay
Description copied from interface:GTaskSchedulerSchedules a task at a delay after each run.- Specified by:
scheduleWithFixedDelayin interfaceGTaskScheduler- Parameters:
initialDelay- Delay before task execution.delay- Delay after task execution.runnable- Task to schedule.- Returns:
- A
GCancelableto cancel the task.
-