Interface Schedulers.Factory

Enclosing class:
Schedulers

public static interface Schedulers.Factory
Public factory hook to override Schedulers behavior globally
  • Method Details

    • newBoundedElastic

      default Scheduler newBoundedElastic(int threadCap, int queuedTaskCap, ThreadFactory threadFactory, int ttlSeconds)
      Scheduler that dynamically creates a bounded number of ExecutorService-based Workers, reusing them once the Workers have been shut down. The underlying (user or daemon) threads can be evicted if idle for more than ttlSeconds.

      The maximum number of created thread pools is bounded by the provided threadCap.

      Parameters:
      threadCap - maximum number of underlying threads to create
      queuedTaskCap - maximum number of tasks to enqueue when no more threads can be created. Can be Integer.MAX_VALUE for unbounded enqueueing.
      threadFactory - a ThreadFactory to use each thread initialization
      ttlSeconds - Time-to-live for an idle Scheduler.Worker
      Returns:
      a new Scheduler that dynamically creates workers with an upper bound to the number of backing threads, reuses threads and evict idle ones
    • newThreadPerTaskBoundedElastic

      default Scheduler newThreadPerTaskBoundedElastic(int threadCap, int queuedTaskCap, ThreadFactory threadFactory)
      Scheduler that dynamically creates a bounded number of Workers.

      The maximum number of created thread pools is bounded by the provided threadCap.

      The main difference between BoundedElasticScheduler and BoundedElasticThreadPerTaskScheduler is that underlying machinery allocates a new thread for every new task which is one of the requirements for usage with VirtualThreads

      Note: for now this scheduler is available only in Java 21+ runtime

      Parameters:
      threadCap - maximum number of underlying threads to create
      queuedTaskCap - maximum number of tasks to enqueue when no more threads can be created. Can be Integer.MAX_VALUE for unbounded enqueueing.
      threadFactory - a ThreadFactory to use each thread initialization
      Returns:
      a new Scheduler that dynamically creates workers with an upper bound to the number of backing threads
      Since:
      3.6.0
    • newParallel

      default Scheduler newParallel(int parallelism, ThreadFactory threadFactory)
      Scheduler that hosts a fixed pool of workers and is suited for parallel work.
      Parameters:
      parallelism - Number of pooled workers.
      threadFactory - a ThreadFactory to use for the fixed initialized number of Thread
      Returns:
      a new Scheduler that hosts a fixed pool of workers and is suited for parallel work
    • newSingle

      default Scheduler newSingle(ThreadFactory threadFactory)
      Scheduler that hosts a single worker and is suited for non-blocking work.
      Parameters:
      threadFactory - a ThreadFactory to use for the unique resource of the Scheduler
      Returns:
      a new Scheduler that hosts a single worker