Class CustomScheduler
java.lang.Object
com.bobocode.bring.core.bpp.impl.schedule.CustomScheduler
Represents a custom scheduler utilizing a ScheduledExecutorService for task scheduling.
This class wraps a ScheduledExecutorService and provides methods to schedule tasks,
as well as to shut down the underlying executor service.
Example usage: Instances of this class can be used to schedule tasks with a defined initial delay, period, and time unit using the wrapped ScheduledExecutorService.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprivate final ScheduledExecutorService
The wrapped ScheduledExecutorService for task scheduling. -
Constructor Summary
ConstructorDescriptionCustomScheduler
(ScheduledExecutorService scheduledExecutorService) Constructs a CustomScheduler with a provided ScheduledExecutorService instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
scheduleTask
(Runnable command, long initialDelay, long period, TimeUnit timeUnit) Schedules a task to run at a fixed rate defined by the initial delay, period, and time unit.void
shutdown()
Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted.void
Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution.
-
Field Details
-
scheduledExecutorService
The wrapped ScheduledExecutorService for task scheduling.
-
-
Constructor Details
-
CustomScheduler
Constructs a CustomScheduler with a provided ScheduledExecutorService instance.- Parameters:
scheduledExecutorService
- the ScheduledExecutorService to be used for scheduling tasks
-
-
Method Details
-
scheduleTask
Schedules a task to run at a fixed rate defined by the initial delay, period, and time unit.- Parameters:
command
- the task to be executedinitialDelay
- the initial delay before the first executionperiod
- the period between successive executionstimeUnit
- the time unit for the initial delay and period- See Also:
-
shutdown
public void shutdown()Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted.- See Also:
-
shutdownNow
public void shutdownNow()Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution.- See Also:
-