File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Timer/ TimerTask" Watch "Timer/ TimerTask" New topic
Author

Timer/ TimerTask

Jaan Smith
Greenhorn

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
Jaan

Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

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
Greenhorn

Joined: Jun 19, 2006
Posts: 5
The solution would be to cancel the timer in run method.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Timer/ TimerTask
 
Similar Threads
problem with classes
How to i invoke a method every 24 hours
To validate telnet connectivity in java code
Threads doubt
Set Timer