public class Scheduler extends Object implements Closeable
ScheduledExecutorService
with core pool size 1. The behaviour
of this underlying scheduler service determines the semantics of the methods
in this class. Namely: Execution of background tasks never overlaps and is
FIFO for tasks scheduled for the same time.
In addition all tasks scheduled through methods of this class are automatically
wrapped into SafeRunnable
instances. The background thread executing
submitted tasks is a deamon thread.Constructor and Description |
---|
Scheduler(String name)
Create a new instance with the given
name . |
Modifier and Type | Method and Description |
---|---|
void |
close()
Close this scheduler.
|
void |
execute(String name,
Runnable task)
Immediately execute
task . |
void |
scheduleAtFixedRate(String name,
long period,
TimeUnit unit,
Runnable task)
Run
task regularly at a given interval. |
void |
scheduleOnce(String name,
long delay,
TimeUnit unit,
Runnable task)
Run
task once after some delay. |
public void execute(@Nonnull String name, @Nonnull Runnable task)
task
. The background thread's name is
set to name
during execution of task
.name
- task
- Executor.execute(Runnable)
public void scheduleOnce(@Nonnull String name, long delay, @Nonnull TimeUnit unit, @Nonnull Runnable task)
task
once after some delay. The background thread's name is
set to name
during execution of task
.name
- delay
- unit
- task
- ScheduledExecutorService.schedule(Runnable, long, TimeUnit)
public void scheduleAtFixedRate(@Nonnull String name, long period, @Nonnull TimeUnit unit, @Nonnull Runnable task)
task
regularly at a given interval. The background thread's name is
set to name
during execution of task
.name
- period
- unit
- task
- ScheduledExecutorService.scheduleAtFixedRate(Runnable, long, long, TimeUnit)
public void close()
close
in interface Closeable
close
in interface AutoCloseable
ExecutorService.shutdown()
Copyright © 2012-2019 The Apache Software Foundation. All Rights Reserved.