When dealing with threads
you should remove phrases like
exactly one second from your vernacular. Having said that you can do something like this to come close to what you want:
A couple of things need to be pointed out here. First when the Timer is created a new thread is spawned so this code effectively requires two threads for each worker thread. Second, this assumes you are using a thread pool for implementation since if you just do something like
new Thread(new TimedRunner()).start() the thread will die when the timer fires. You could get around this using events or the observer
pattern and wrapping the work loop in another loop that waits on this and the external event could signal the thread to wake up with notify or notifyAll.
[ March 14, 2004: Message edited by: Michael Morris ]
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher