This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Java in General and the fly likes Timer doesnt work 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 doesnt work" Watch "Timer doesnt work" New topic
Author

Timer doesnt work

adeeb alexander
Ranch Hand

Joined: May 29, 2008
Posts: 268
Hi all.
The code below doesnt give any output. Anyone can please help where it is wrong.


Thanks & Regards
Adeeb
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24189
    
  34

What's happening here is that running Timer won't keep the JVM from exiting. You start a timer, and then main() returns; at that point, the program stops, long before the Timer fires. If you added a line line

try { Thread.sleep(70000); } catch (InterruptedException ex) {}

to the end of your program, main will sleep until after the Timer fires, and you will see your output.


[Jess in Action][AskingGoodQuestions]
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Timer doesnt work
 
It's not a secret anymore!