|
Bali Share 1.1.18 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--oracle.bali.share.thread.Timer
A Timer is an object that will wait a user-defined length of time and then call a user-specified target. The delay is not guaranteed to be accurate; the delay may be greater than requested. However, the delay will never be less than requested. To implement drift-free timing, use the getMillisSinceExpired() method.
Timers may be rescheduled or cancelled at any time, but they are not destroyed until the kill() method is explicitly called.
Constructor Summary | |
Timer(java.lang.Runnable target)
Constructs a new timer for the specified target. |
|
Timer(java.lang.Runnable target,
long delay)
Constructs a new timer for the specified target, immediately scheduling it. |
|
Timer(java.lang.Runnable target,
java.lang.String name)
Constructs a new timer for the specified target, with a given name. |
Method Summary | |
protected void |
accurateSleep(long millis)
Sleeps the current thread for the designated number of milliseconds; attempting to be more accurate than the built-in Thread.sleep() function. |
void |
cancel()
Cancels a scheduled timer. |
protected void |
doRun()
Actually runs the target. |
protected void |
finalize()
Cleans up the timer. |
protected java.lang.String |
getDefaultName()
Returns the default name for the timer. |
long |
getDelay()
Returns the current delay, in milliseconds. |
long |
getMillisSinceExpired()
Returns the milliseconds between when the current time and the actual time when the timer should have expired. |
java.lang.String |
getName()
Gets the name of the timer. |
int |
getPriority()
Gets and returns the priority of the timer. |
boolean |
isDaemon()
Tests if this timer is a daemon timer. |
boolean |
isKilled()
|
boolean |
isScheduled()
Returns TRUE if the timer has been scheduled. |
void |
kill()
Kills a timer. |
void |
run()
Target function for timer thread. |
void |
schedule(long delay)
Schedules a timer. |
void |
setDaemon(boolean on)
Marks this timer as either a daemon timer or a user timer. |
void |
setDelay(long delay)
Sets the current delay, in milliseconds. |
void |
setName(java.lang.String name)
Sets the name of the timer. |
void |
setPriority(int newPriority)
Sets the timer's priority. |
protected boolean |
wasCancelledDuringRun()
Returns TRUE if cancel was called during the run. |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Timer(java.lang.Runnable target)
target
- the Runnable objectpublic Timer(java.lang.Runnable target, java.lang.String name)
target
- the Runnable objectname
- the new name for any threads used by the timer.public Timer(java.lang.Runnable target, long delay)
target
- the Runnable objectdelay
- the length of time in milliseconds to sleepMethod Detail |
public void schedule(long delay)
delay
- the length of time to sleep in millisecondsisScheduled()
,
getDelay()
public boolean isScheduled()
schedule(long)
,
getDelay()
public long getDelay()
schedule(long)
,
isScheduled()
public void setDelay(long delay)
delay
- the length of time to sleep in millisecondspublic long getMillisSinceExpired()
public void cancel()
schedule(long)
,
kill()
,
wasCancelledDuringRun()
public void kill()
cancel()
public boolean isKilled()
public void setName(java.lang.String name)
name
- the new name for any threads used by the timer.public java.lang.String getName()
public void setDaemon(boolean on)
This method must be called before the timer has ever been scheduled, or an IllegalThreadStateException will be thrown.
on
- if true, marks this timer as a daemon timerIllegalThreadStateException
- if this timer has been
scheduled.public boolean isDaemon()
public void setPriority(int newPriority)
newPriority
- timer's new prioritypublic int getPriority()
public void run()
run
in interface java.lang.Runnable
schedule(long)
,
doRun()
protected void accurateSleep(long millis) throws java.lang.InterruptedException
millis
- the number of milliseconds to sleep.java.lang.InterruptedException
- Another thread has interrupted this thread.Thread.sleep(long)
protected void doRun()
protected boolean wasCancelledDuringRun()
protected java.lang.String getDefaultName()
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
- Any exception thrown by a finalize method causes
finalization to halt; otherwise, it is ignored.
|
Bali Share 1.1.18 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |