Mega Code Archive

 
Categories / Java Book / 007 Thread Conncurrent
 

0391 Timer and TimerTask

Timer schedules a task for execution at some future time. Timer and TimerTask do the scheduling. Using Timer, you can create a thread that runs in the background, waiting for a specific time. When the time arrives, the task linked to that thread is executed. You can schedule a task for repeated execution. Or you can schedule a task to run on a specific date. Timer is the class that you will use to schedule a task for execution. The scheduled task is an instance of TimerTask. TimerTask implements the Runnable interface.