while (timedThread != null) {
System.out.println("About to sleep for " + time + "mSec");
try {
Thread.sleep(time);
} catch (InterruptedException ie) {
System.err.println("Unexpectedly interrupted time sleep!");
return;
}
if (timedThread == null)
return;
// if we are still here, the timer went off, but the
// main program hasn't nullified the thread yet.
System.out.println("Will now interrupt sleep of " + timedThread);
timedThread.interrupt();
}