public class Timer
extends java.lang.Object
implements java.lang.Runnable, java.io.Serializable
The timer (and the calls to the method) will be running in another thread that is not the application thread.
Modifier and Type | Class and Description |
---|---|
static interface |
Timer.TimerTick
This is the interface that must be implemented by classes that
will receive events at the intervals indicated by the Timer
class when the timer is running.
|
Constructor and Description |
---|
Timer(Timer.TimerTick target,
long waitTime,
float position,
boolean bInSeparateThread)
Creates a Timer that will be in not running status until
start() is called. |
Timer(Timer.TimerTick target,
long waitTime1,
long waitTime2,
java.lang.String timerName,
boolean bInSeparateThread)
Creates a Timer that will be in not running status until
start() is called. |
Modifier and Type | Method and Description |
---|---|
boolean |
isRunning()
Checks if is running.
|
void |
processEvents(boolean value)
Under normal operations, a Timer always process timing events.
|
void |
run()
Run.
|
void |
start()
Starts the execution of the timer.
|
void |
stop()
Stops the timer exection.
|
public Timer(Timer.TimerTick target, long waitTime, float position, boolean bInSeparateThread)
start()
is called.target
- the instance of the class implementing the TimerTick interface.waitTime
- the duration of the wait intervalposition
- the relative position in the wait interval when the timerEvent method will be called. This
is a number between 0 and 1. If 0, the initial time does not exists. When the timer is started, the timerEvent
will be immediately called. if it is 1, the initial time must completely pass until the timerEvent is called
for the first timebInSeparateThread
- if this is true, timerEvent will be called in a separate thread. If this is false,
timerEvent will be called in the same thread the timer is runningpublic Timer(Timer.TimerTick target, long waitTime1, long waitTime2, java.lang.String timerName, boolean bInSeparateThread)
start()
is called.target
- the instance of the class implementing the TimerTick interface.waitTime1
- the duration of the wait interval from the moment the timer is started till the moment the timerEvent is called.waitTime2
- the duration of the wait interval from the moment the timerEvent is called till the next execution is restarted.timerName
- this is the name assigned to the timer thread.bInSeparateThread
- if this is true, timerEvent will be called in a separate thread. If this is false,
timerEvent will be called in the same thread the timer is runningpublic void run()
run
in interface java.lang.Runnable
public void start() throws java.lang.IllegalThreadStateException
java.lang.IllegalThreadStateException
- the illegal thread state exceptionpublic void stop()
public boolean isRunning()
public void processEvents(boolean value)
value
- the valueCopyright 2006-2015 Reporting Standard S.L., C/ Torrecilla del Puerto 1, 28043, Madrid, Espaņa