@Documented @Retention(value=RUNTIME) @Target(value=TYPE) public @interface ScheduleWithFixedDelay
For example, you want a method to do something every minute:
@ScheduleWithFixedDelay(delay = 1, unit = TimeUnit.MINUTES) public class Bucket implements Runnable, Closeable { @Override void run() { // do some routine job } @Override void close() { // close operations } }
Execution will be started as soon as you make an instance of the class,
and will be stopped when you call close()
:
Bucket bucket = new Bucket(); // some time later bucket.close();
In order to be executed the class should implement either
Runnable
or Callable
. In order to
be closed and stopped, your the class should implement
Closeable
and its close()
method should be explicitly called
at the moment you want it to stop.
Modifier and Type | Optional Element and Description |
---|---|
int |
await
How long to wait for the task to finish after shutdown in await units.
|
TimeUnit |
awaitUnit
Time units of await time.
|
int |
delay
Delay, in time units.
|
int |
shutdownAttempts
How many times to do a forceful shutdown after await time.
|
int |
threads
Total number of fixed threads.
|
TimeUnit |
unit
Time units of delay.
|
public abstract int delay
public abstract TimeUnit unit
public abstract int await
public abstract TimeUnit awaitUnit
public abstract int shutdownAttempts
public abstract int threads
Copyright © 2012–2014 jcabi.com. All rights reserved.