public class Timeout
extends java.lang.Object
When a timeout object is created, it is given a task to run and a length of time after which to run the task. However, the timeout is created in an inactive state. To start the timeout countdown, the start() method must be called. Once the timeout is started, the timeout may be cancelled using the cancel() method, or reset via reset(). The reset() method effectively resets the timeout as if cancel() and then start() had been called, but does so in a way that does not create any new objects or start any new threads, and is thus safe to call frequently if needed, rather than calling cancel() followed by start().
Constructor and Description |
---|
Timeout(int length,
java.lang.Runnable task)
Creates a new timeout.
|
Modifier and Type | Method and Description |
---|---|
void |
cancel()
Cancels the timeout.
|
void |
reset()
Resets the elapsed time back to zero and continues the timeout.
|
void |
start()
Resets the elapsed time and starts the timeout countdown.
|
public Timeout(int length, java.lang.Runnable task)
length
- the timeout length in milliseconds.task
- the runnable task to perform when the timeout occurs.public void reset()
public void start()
public void cancel()