public class Alarm extends Thread
In principle the functionality of the alarm can be constructed using the java Timer and TimerTask classes but the simplicity of this class may provide a very easy and convenient access.
| Modifier and Type | Class and Description |
|---|---|
static class |
Alarm.Test
Test purpose only.
|
Thread.State, Thread.UncaughtExceptionHandler| Modifier and Type | Field and Description |
|---|---|
private double |
accelerate
System-wide acceleration.
|
protected AlarmHandler |
alarmList
The alarm handlers
|
private boolean |
alarmOff
Gets true if the alarm is canceled.
|
private static int |
COUNT
An internal counter for automatic naming.
|
private long |
mintime
The time-tag that must be reached.
|
private long |
starttime
The first time-tag that must be reached.
|
private long |
sustime
The time the
Thread.suspend() method was called. |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY| Modifier | Constructor and Description |
|---|---|
protected |
Alarm()
Constructor chaining, do not use.
|
|
Alarm(AlarmHandler ear,
Date when)
Constructs a new alarm with a default name and starts it automatically.
|
|
Alarm(AlarmHandler ear,
long timeout)
Constructs a new alarm with a default name and starts it automatically.
|
|
Alarm(ThreadGroup group,
String name,
AlarmHandler ear,
Date when)
Constructs a new alarm and starts it automatically.
|
|
Alarm(ThreadGroup group,
String name,
AlarmHandler ear,
long timeout)
Constructs a new alarm and starts it automatically.
|
| Modifier and Type | Method and Description |
|---|---|
void |
cancel()
Cancels this alarm.
|
private static int |
nextCount()
Gets the next available number at automatic naming.
|
void |
restartTimeout(long timeout)
If this alarm has not yet set off, you can allocate a new timeout to it.
|
void |
resumeAlarm()
Resumes the alarm-clock ticking after a call to
suspendAlarm(). |
void |
run()
The run method of the alarm.
|
protected void |
setOffAlarm()
This method sets off all registered alarm listeners by calling their
setOff method.
|
void |
suspendAlarm()
Temporarily pauses the alarm clock.
|
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yieldprotected AlarmHandler alarmList
private boolean alarmOff
private long mintime
private long starttime
private double accelerate
private long sustime
Thread.suspend() method was called.private static int COUNT
protected Alarm()
public Alarm(AlarmHandler ear, Date when)
ear - The alarm handlers to notify.when - The date when the alarm is set off.public Alarm(AlarmHandler ear, long timeout)
ear - The alarm handlers to notify.timeout - The time till alarm is set off, in ms.IllegalArgumentException - If timeout is negative.public Alarm(ThreadGroup group, String name, AlarmHandler ear, Date when)
group - The thread group this alarm should run in.name - The name for the alarmear - The alarm handlers to notify.when - The date when the alarm is set off.public Alarm(ThreadGroup group, String name, AlarmHandler ear, long timeout)
group - The thread group this alarm should run in.name - The name for the alarmear - The alarm listeners to notify.timeout - The time till alarm is set off, in ms.IllegalArgumentException - If timeout is negative.private static int nextCount()
public final void suspendAlarm()
resumeAlarm() method is called.public final void resumeAlarm()
suspendAlarm().public final void restartTimeout(long timeout)
timeout - public final void run()
cancel() method but if this thread is interrupted the same effect
should be obtained.protected void setOffAlarm()
public void cancel()