Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Timer doesnt work

 
adeeb alexander
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic