public final class SingleScheduler extends Scheduler
Scheduler.Worker
Constructor and Description |
---|
SingleScheduler() |
SingleScheduler(ThreadFactory threadFactory) |
Modifier and Type | Method and Description |
---|---|
Scheduler.Worker |
createWorker()
Retrieves or creates a new
Scheduler.Worker that represents sequential execution of actions. |
Disposable |
scheduleDirect(Runnable run,
long delay,
TimeUnit unit)
Schedules the execution of the given task with the given time delay.
|
Disposable |
schedulePeriodicallyDirect(Runnable run,
long initialDelay,
long period,
TimeUnit unit)
Schedules a periodic execution of the given task with the given initial time delay and repeat period.
|
void |
shutdown()
Instructs the Scheduler instance to stop threads,
stop accepting tasks on any outstanding
Scheduler.Worker instances
and clean up any associated resources with this Scheduler. |
void |
start()
Allows the Scheduler instance to start threads
and accept tasks on them.
|
clockDriftTolerance, now, scheduleDirect, when
public SingleScheduler()
public SingleScheduler(ThreadFactory threadFactory)
threadFactory
- thread factory to use for creating worker threads. Note that this takes precedence over any
system properties for configuring new thread creation. Cannot be null.public void start()
Scheduler
Implementations should make sure the call is idempotent, thread-safe and
should not throw any RuntimeException
if it doesn't support this
functionality.
public void shutdown()
Scheduler
Scheduler.Worker
instances
and clean up any associated resources with this Scheduler.
Implementations should make sure the call is idempotent, thread-safe and
should not throw any RuntimeException
if it doesn't support this
functionality.
@NonNull public Scheduler.Worker createWorker()
Scheduler
Scheduler.Worker
that represents sequential execution of actions.
When work is completed, the Worker
instance should be released
by calling Disposable.dispose()
to avoid potential resource leaks in the
underlying task-execution scheme.
Work on a Scheduler.Worker
is guaranteed to be sequential and non-overlapping.
createWorker
in class Scheduler
@NonNull public Disposable scheduleDirect(@NonNull Runnable run, long delay, TimeUnit unit)
Scheduler
This method is safe to be called from multiple threads but there are no ordering guarantees between tasks.
scheduleDirect
in class Scheduler
run
- the task to scheduledelay
- the delay amount, non-positive values indicate non-delayed schedulingunit
- the unit of measure of the delay amount@NonNull public Disposable schedulePeriodicallyDirect(@NonNull Runnable run, long initialDelay, long period, TimeUnit unit)
Scheduler
This method is safe to be called from multiple threads but there are no ordering guarantees between tasks.
The periodic execution is at a fixed rate, that is, the first execution will be after the
initialDelay
, the second after initialDelay + period
, the third after
initialDelay + 2 * period
, and so on.
schedulePeriodicallyDirect
in class Scheduler
run
- the task to scheduleinitialDelay
- the initial delay amount, non-positive values indicate non-delayed schedulingperiod
- the period at which the task should be re-executedunit
- the unit of measure of the delay amountCopyright © 2018 JBoss by Red Hat. All rights reserved.