Class ScalingNetworkTaskScheduler

java.lang.Object
eu.cloudnetservice.driver.impl.network.scheduler.ScalingNetworkTaskScheduler
All Implemented Interfaces:
NetworkTaskScheduler, Executor

public final class ScalingNetworkTaskScheduler extends Object implements NetworkTaskScheduler
An implementation of a network task scheduler that slowly starts more threads depending on the count of tasks that couldn't be scheduled into the core executor service. If more and more tasks are starting to come in and the core thread pool is not able to keep up, the pace of starting new threads increases. Initially the time between thread starts is 2.5 seconds, and it can go all the way down to 100ms if needed (starting at around 160 tasks waiting to be scheduled).
Since:
4.0
  • Field Details

  • Constructor Details

    • ScalingNetworkTaskScheduler

      public ScalingNetworkTaskScheduler(@NonNull @NonNull ThreadFactory threadFactory, int maximumCorePoolSize)
      Constructs a new scaling task executor.
      Parameters:
      threadFactory - the thread factory to use when the underlying executors create new threads.
      maximumCorePoolSize - the maximum threads that the core executor can use.
      Throws:
      NullPointerException - if the given thread factory is null.
      IllegalArgumentException - if the given maximum pool size is smaller than 0.
  • Method Details

    • shutdown

      public void shutdown()
      Triggers a shutdown operation on this scheduler, interrupting all currently running tasks and preventing new tasks from being scheduled.
      Specified by:
      shutdown in interface NetworkTaskScheduler
    • execute

      public void execute(@NonNull @NonNull Runnable command)
      Specified by:
      execute in interface Executor