public final class TimerTask
extends java.util.TimerTask
eBus.util.TimerTask
associates a timer
task with a TimerTaskListener
. When the timer expires,
TimerTaskListener.handleTimeout(TimerEvent)
where
EventObject.getSource()
returns the value passed to
the TimerTask(TimerTaskListener, Object)
constructor.
In eBus v. 4.2.0, TimerTaskListener
is marked as a
@FunctionalInterface
. This allows the listener to be
defined using a lambda expression.
If TimerTaskListener.handleTimeout(TimerEvent)
throws
an exception, the exception stack trace is logged at the
warning level.
Constructor and Description |
---|
TimerTask(TimerTaskListener listener)
Creates a new
TimerTask . |
TimerTask(TimerTaskListener listener,
java.lang.Object value)
Creates a new
TimerTask . |
Modifier and Type | Method and Description |
---|---|
boolean |
cancel()
Cancels this timer task.
|
void |
run()
Tells the listener that this timer has expired.
|
java.lang.Object |
value()
Returns optional value associated with this timer task.
|
public TimerTask(TimerTaskListener listener)
TimerTask
. This task
is sent to the TimerTaskListener
when the
timer expires. The associated value is null
.listener
- Inform this listener of the timeout.java.lang.NullPointerException
- if listener
is null
.public TimerTask(TimerTaskListener listener, java.lang.Object value)
TimerTask
. This task
is sent to
TimerTaskListener.handleTimeout(TimerEvent)
when the timer expires. The associated value is
value
.listener
- Inform this listener of the timeout.value
- The associated value passed to the listener.
May be null
.java.lang.NullPointerException
- if listener
is null
.public boolean cancel()
java.util.TimerTask.cancel
for a
detailed description of cancel.cancel
in class java.util.TimerTask
true
if this timer task is scheduled to
run once and never ran or is scheduled for repeated
execution. Returns false
if this task was
scheduled to run once and was executed, if this task
was never scheduled or if this task is already canceled.public void run()
Note: Do not call this method! This method is part
of java.util.TimerTask
and should be called
by java.util.Timer
only.
run
in interface java.lang.Runnable
run
in class java.util.TimerTask
@Nullable public java.lang.Object value()
null
.Copyright © 2001 - 2024. Charles W. Rapp. All rights reserved.