36 |
|
* @see Executors |
37 |
|
* |
38 |
|
* @spec JSR-166 |
39 |
+ |
* @author Doug Lea |
40 |
|
*/ |
41 |
|
public class ScheduledExecutor extends ThreadPoolExecutor { |
42 |
|
|
50 |
|
* A delayed or periodic action. |
51 |
|
*/ |
52 |
|
public static class DelayedTask extends CancellableTask implements Delayed { |
53 |
+ |
/** Sequence number to break ties FIFO */ |
54 |
|
private final long sequenceNumber; |
55 |
+ |
/** The time the task is enabled to execute in nanoTime units */ |
56 |
|
private final long time; |
57 |
+ |
/** The delay forllowing next time, or <= 0 if non-periodic */ |
58 |
|
private final long period; |
59 |
< |
private final boolean rateBased; // true if at fixed rate; |
60 |
< |
// false if fixed delay |
59 |
> |
/** true if at fixed rate; false if fixed delay */ |
60 |
> |
private final boolean rateBased; |
61 |
> |
|
62 |
|
/** |
63 |
|
* Creates a one-shot action with given nanoTime-based trigger time |
64 |
|
*/ |
104 |
|
|
105 |
|
/** |
106 |
|
* Return true if this is a periodic (not a one-shot) action. |
107 |
+ |
* @return true if periodic |
108 |
|
*/ |
109 |
|
public boolean isPeriodic() { |
110 |
|
return period > 0; |
112 |
|
|
113 |
|
/** |
114 |
|
* Returns the period, or zero if non-periodic |
115 |
+ |
* @return the period |
116 |
|
*/ |
117 |
|
public long getPeriod(TimeUnit unit) { |
118 |
|
return unit.convert(period, TimeUnit.NANOSECONDS); |
280 |
|
} |
281 |
|
|
282 |
|
/** |
283 |
< |
* Creates and executes a one-shot action that becomes enabled after the given date. |
283 |
> |
* Creates and executes a one-shot action that becomes enabled |
284 |
> |
* after the given date. |
285 |
|
* @param command the task to execute. |
286 |
|
* @param date the time to commence excution. |
287 |
|
* @return a handle that can be used to cancel the task. |
438 |
|
/** |
439 |
|
* If executed task was periodic, cause the task for the next |
440 |
|
* period to execute. |
441 |
+ |
* @param r the task (assumed to be a DelayedTask) |
442 |
+ |
* @param t the exception |
443 |
|
*/ |
444 |
|
protected void afterExecute(Runnable r, Throwable t) { |
445 |
|
if (isShutdown()) |