Top Description Inners Fields Constructors Methods
reactor.core.scheduler

pack-priv final Class BoundedElasticScheduler

extends Object
implements Scheduler, SchedulerState.DisposeAwaiter<BoundedElasticScheduler.BoundedServices>, Scannable
Class Inheritance
All Implemented Interfaces
reactor.core.Scannable, reactor.core.scheduler.SchedulerState.DisposeAwaiter, reactor.core.scheduler.Scheduler, reactor.core.Disposable
Imports
reactor.core.Disposable, .Disposables, .Exceptions, .Scannable, reactor.core.publisher.Mono, reactor.util.Logger, .Loggers, reactor.util.annotation.Nullable, java.time.Clock, .Instant, .ZoneId, java.util.ArrayList, .Collection, .Collections, .Deque, .List, .Objects, .PriorityQueue, java.util.concurrent.Callable, .ConcurrentLinkedDeque, .ExecutionException, .Executors, .Future, .RejectedExecutionException, .RejectedExecutionHandler, .ScheduledExecutorService, .ScheduledFuture, .ScheduledThreadPoolExecutor, .ThreadFactory, .ThreadPoolExecutor, .TimeUnit, .TimeoutException, java.util.concurrent.atomic.AtomicInteger, .AtomicIntegerFieldUpdater, .AtomicLong, .AtomicReferenceFieldUpdater, java.util.stream.Stream

Scheduler that hosts a pool of 0-N single-threaded BoundedScheduledExecutorService and exposes workers backed by these executors, making it suited for moderate amount of blocking work. Note that requests for workers will pick an executor in a round-robin fashion, so tasks from a given worker might arbitrarily be impeded by long-running tasks of a sibling worker (and tasks are pinned to a given executor, so they won't be stolen by an idle executor). This scheduler is time-capable (can schedule with delay / periodically).
Author
Simon Baslé

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
pack-priv static class
pack-priv static class
BoundedElasticScheduler.BoundedState

A class that encapsulate state around the BoundedScheduledExecutorService and atomically marking them picked/idle.

Field Summary

Modifier and TypeField and Description
pack-priv final Clock
pack-priv static final AtomicLong
pack-priv static final int
pack-priv final ThreadFactory
private static final SchedulerState<BoundedElasticScheduler.BoundedServices>
pack-priv static final Logger
pack-priv final int
pack-priv final int
pack-priv volatile SchedulerState<BoundedElasticScheduler.BoundedServices>
pack-priv static final AtomicReferenceFieldUpdater<BoundedElasticScheduler, SchedulerState<T>>
pack-priv final long

Constructor Summary

AccessConstructor and Description
pack-priv
BoundedElasticScheduler(int maxThreads, int maxTaskQueuedPerThread, ThreadFactory threadFactory, long ttlMillis, Clock clock)

This constructor lets define millisecond-grained TTLs and a custom Clock, which can be useful for tests.

pack-priv
BoundedElasticScheduler(int
the maximum number of backing threads to spawn, must be strictly positive
maxThreads
,
int
the maximum amount of tasks an executor can queue up
maxTaskQueuedPerThread
,
ThreadFactory
the ThreadFactory to name the backing threads
factory
,
int
the time-to-live (TTL) of idle threads, in seconds
ttlSeconds
)

Create a BoundedElasticScheduler with the given configuration.

Method Summary

Modifier and TypeMethod and Description
public boolean
pack-priv BoundedElasticScheduler.BoundedScheduledExecutorService
createBoundedExecutorService()

Instantiates the default ScheduledExecutorService for the scheduler (Executors.newScheduledThreadPoolExecutor with core and max pool size of 1).

public Scheduler.Worker
createWorker()

Implements reactor.core.scheduler.Scheduler.createWorker.

Creates a worker of this Scheduler.
public void
dispose()

Overrides default reactor.core.scheduler.Scheduler.dispose.

Instructs this Scheduler to release all resources and reject any new tasks to be executed.
public Mono<Void>
disposeGracefully()

Overrides default reactor.core.scheduler.Scheduler.disposeGracefully.

Lazy variant of dispose() that also allows for graceful cleanup of underlying resources.
pack-priv int

Returns:

a best effort total count of the busy executors
estimateBusy
()

pack-priv int

Returns:

a best effort total count of the idle executors
estimateIdle
()

pack-priv int

Returns:

the total task capacity, or -1 if any backing executor's task queue size cannot be instrumented
estimateRemainingTaskCapacity
()

Best effort snapshot of the remaining queue capacity for pending tasks across all the backing executors.

pack-priv int

Returns:

a best effort total count of the spinned up executors
estimateSize
()

public void
init()

Overrides default reactor.core.scheduler.Scheduler.init.

Instructs this Scheduler to prepare itself for running tasks directly or through its Workers.
public Stream<? extends Scannable>
inners()

Overrides default reactor.core.Scannable.inners.

Return a Stream of referenced inners (flatmap, multicast etc)
public boolean
isDisposed()

Overrides default reactor.core.Disposable.isDisposed.

Optionally return true when the resource or task is disposed.
public Object
scanUnsafe(Scannable.Attr<T>
a Attr to resolve for the component.
key
)

Implements reactor.core.Scannable.scanUnsafe.

This method is used internally by components to define their key-value mappings in a single place.
public Disposable
schedule(Runnable
the task to execute
task
)

Implements reactor.core.scheduler.Scheduler.schedule.

Schedules the non-delayed execution of the given task on this scheduler.
public Disposable
schedule(Runnable
the task to schedule
task
,
long
the delay amount, non-positive values indicate non-delayed scheduling
delay
,
TimeUnit
the unit of measure of the delay amount
unit
)

Overrides default reactor.core.scheduler.Scheduler.schedule.

Schedules the execution of the given task with the given delay amount.
public Disposable
schedulePeriodically(Runnable
the task to schedule
task
,
long
the initial delay amount, non-positive values indicate non-delayed scheduling
initialDelay
,
long
the period at which the task should be re-executed
period
,
TimeUnit
the unit of measure of the delay amount
unit
)

Overrides default reactor.core.scheduler.Scheduler.schedulePeriodically.

Schedules a periodic execution of the given task with the given initial delay and period.
public void
start()

Overrides default reactor.core.scheduler.Scheduler.start.

Instructs this Scheduler to prepare itself for running tasks directly or through its Workers.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait