Methods Summary |
---|
public synchronized void | blockingPause()Same as pause except that it blocks until the loop has actually
paused (at waitHereIfPaused).
if (waitingAtPaused || killed) return;
paused = true;
waitForCompleteStop();
|
public boolean | isPaused()
return paused;
|
public synchronized void | kill()
killed = true;
notifyAll();
|
public synchronized void | pause()Set the paused state to true. The thread will halt at the
beginning of the loop at the next iteration. i.e., unlike
suspend(), the thread will NOT pause immediately. It will execute
until the next waitHereIfPaused() is encountered.
paused = true;
|
protected abstract boolean | process()process callback function.
|
public void | run()The run method for the Thread class.
for (;;) {
// Wait here if pause() was invoked. Until start() is called,
// the thread will wait here indefinitely.
if (!waitHereIfPaused())
break;
// Invoke the callback function.
if (!process())
break;
}
|
public synchronized void | start()Resume the loop at the beginning of the loop where
waitHereIfPaused() is called.
if (!started) {
super.start();
started = true;
}
paused = false;
notifyAll();
|
public synchronized void | waitForCompleteStop()Wait until the loop has come to a complete stop.
try {
while (!killed && !waitingAtPaused && paused)
wait();
} catch (InterruptedException e) { }
|
public synchronized void | waitForCompleteStop(int millis)Wait until the loop has come to a complete stop.
Time out after the given milli seconds.
try {
if (!killed && !waitingAtPaused && paused)
wait(millis);
} catch (InterruptedException e) { }
|
public synchronized boolean | waitHereIfPaused()Put the thread in a wait() if the paused state is on. Otherwise, it
will just proceed.
if (killed)
return false;
waitingAtPaused = true;
if (paused)
notifyAll(); // notify the blocking pause.
try {
while (!killed && paused)
wait();
} catch (InterruptedException e) {
System.err.println("Timer: timeLoop() wait interrupted " + e);
}
waitingAtPaused = false;
if (killed)
return false;
return true;
|