• Post Reply Bookmark Topic Watch Topic
  • New Topic

System.exit() and Timer  RSS feed

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Could anyone explain how actually I can add to code Timer before execution of System.exit(0) for example for 5 seconds ? Do I need to use TimerTask? How to construct Timer, I should create method or declare it as instance variable ?

 
Sheriff
Posts: 22845
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand the question. You apparently want to create a Timer object, but you don't say why. And you apparently want to have your program terminate via System.exit(0), but you don't say what this has to do with your Timer object.

I can say this: there is no point creating a Timer object unless you plan to schedule a TimerTask object with it. So yes, you do need to use TimerTask. But beyond that I have no idea what your question is about.
 
Ranch Hand
Posts: 41
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gennadiy Rabkin wrote:Hi
Could anyone explain how actually I can add to code Timer before execution of System.exit(0) for example for 5 seconds ? Do I need to use TimerTask? How to construct Timer, I should create method or declare it as instance variable ?



There is something called Thread.sleep(int milliseconds). Use that for making it wait for certain amount of time.
In java there is something called wait which actually waits for another thread but thats totally different.
 
Gennadiy Rabkin
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thread.sleep are awesome!! Thank you nithin chinni a lot, I've got what I need. Paul Clapham Thank you too.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!