public class Timer extends Object
Timeout
objects) may be
scheduled by calling either of the after()
methods.
Recurring events (controlled by Clock
objects) may be scheduled by
calling either of the every()
methods.Event notification is guaranteed to be prompt but not immediate: the event handler will be invoked no sooner than scheduled and as soon thereafter as possible, but no guarantees are offered that somewhat more time will not have passed than was requested. In particular, while the scheduling API lets you specify times with millisecond precision, millisecond accuracy in practice should not be assumed.
Modifier and Type | Method and Description |
---|---|
Timeout |
after(long millis,
TimeoutNoticer target)
Sets a timeout for the specified number of milliseconds.
|
Timeout |
after(long millis,
TimeoutNoticer target,
boolean synchronous)
Sets a timeout for the specified number of milliseconds.
|
Clock |
every(long resolution,
TickNoticer target)
Creates a new clock.
|
Clock |
every(long resolution,
TickNoticer target,
boolean synchronous)
Creates a new clock.
|
static Timer |
theTimer()
Return the single permitted Timer instance.
|
public Timeout after(long millis, TimeoutNoticer target, boolean synchronous)
noticeTimeout()
method is called.millis
- How long to wait until timing out.target
- Object to be informed when the time comes.synchronous
- Flag controlling synchronous notification of the
timeout. If true, notify synchronously; if false,
post notification on the message queue. Note that great care should
be taken with synchronous notification as it introduces threading
issues; do not use synchronous notification unless you understand
these issues thoroughly (and, by the way, you don't).TimeoutNoticer
public Timeout after(long millis, TimeoutNoticer target)
noticeTimeout()
method is called. Notification is always asynchronous:
this method is equivalent to the after(long,TimeoutNoticer,boolean)
method where the
synchronous argument is set to false.millis
- How long to wait until timing out.target
- Object to be informed when the time comes.TimeoutNoticer
public Clock every(long resolution, TickNoticer target, boolean synchronous)
start()
method).resolution
- The clock tick interval.target
- Object to be sent tick notifications.synchronous
- Flag controlling synchronous notification of clock
ticks. If true, notify synchronously; if false,
post notification on the message queue. Note that great care should
be taken with synchronous notification as it introduces threading
issues; do not use synchronous notification unless you understand
these issues thoroughly.TickNoticer
public Clock every(long resolution, TickNoticer target)
start()
method). Clock ticks are always asynchronous: this method is
equivalent to the every(long,TickNoticer,boolean)
method where
the synchronous argument is set to false.resolution
- The clock tick interval.target
- Object to be sent tick notifications.TickNoticer
public static Timer theTimer()
Copyright © 2017. All rights reserved.