I'm trying to setup a "check-in" thread in my program that will throw an exception if another thread doesn't perform a "check-in" command before time is up. If another thread does check-in before time is up, the timer resets and listens for another check-in.
I'm not overly familiar with Java's Timer object, but I'm assuming the best way to do this would be using the Timer, as the only other method I can think of is starting a new thread with a Thread.sleep(time)
and interrupting it before it wakes, then re-instantiating/starting it; if it gets through the Thread.sleep(time)
it throws the exception. This seems extremely crude and inefficient, though.
So, the basic idea is this:
- Start some kind of timer with a "timeout" of 60 seconds.
- If the timeout is reached, an exception is thrown.
- If another thread "checks-in" before timer times out, the timer resets.
How can I properly do this?