Class CustomScheduler

java.lang.Object
com.bobocode.bring.core.bpp.impl.schedule.CustomScheduler

public class CustomScheduler extends Object
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

    Fields
    Modifier and Type
    Field
    Description
    The wrapped ScheduledExecutorService for task scheduling.
  • Constructor Summary

    Constructors
    Constructor
    Description
    CustomScheduler(ScheduledExecutorService scheduledExecutorService)
    Constructs a CustomScheduler with a provided ScheduledExecutorService instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    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
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • scheduledExecutorService

      private final ScheduledExecutorService scheduledExecutorService
      The wrapped ScheduledExecutorService for task scheduling.
  • Constructor Details

    • CustomScheduler

      public CustomScheduler(ScheduledExecutorService scheduledExecutorService)
      Constructs a CustomScheduler with a provided ScheduledExecutorService instance.
      Parameters:
      scheduledExecutorService - the ScheduledExecutorService to be used for scheduling tasks
  • Method Details

    • scheduleTask

      public void 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.
      Parameters:
      command - the task to be executed
      initialDelay - the initial delay before the first execution
      period - the period between successive executions
      timeUnit - 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: