|
Threads are how you do things in Java. They have been built into the language from the very first.
A cruder approach would be to put a Thread.sleep(50)
in your loop. But the real Java way is to have a separate timer thread, and use
CyclicBarrier or Semaphore to communicate.
The timer thread approach is more robust, as it can keep time independently of the worker thread. This is good, because you don't know how long each task is going to take the worker to do.
|