This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Java in General and the fly likes Timer/ TimerTask Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Java in General
Bookmark "Timer/ TimerTask" Watch "Timer/ TimerTask" New topic

Timer/ TimerTask

Jaan Smith

Joined: Jun 19, 2006
Posts: 5
How to schedule a timer only once. and when done with the task, the program should terminate. In my program the program does not terminates.
Thaks in Advance

Deepak Bala

Joined: Feb 24, 2006
Posts: 6661

Many ways. Do a Thread.sleep() or object.wait() instead of a timer. Or perform a system.exit(0) once you are done printing your name.

SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Jaan Smith

Joined: Jun 19, 2006
Posts: 5
The solution would be to cancel the timer in run method.
GeeCON Prague 2014
subject: Timer/ TimerTask