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

Implementing sleep() like funtionality in a non threaded class

 
Jay Dilla
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the best approach to this?
Is it even possible?
I'm trying to find the sleep() implementation but now realizing it might not even be relevant if it's not a thread.
Are there any other java methods that pause action for a specified period of time?
 
Matthew Brown
Bartender
Posts: 4567
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All code runs in a thread, so you can always call sleep() to wait for a while. Just be aware that if that's the only thread in the application then nothing will happen while it sleeps.
 
Gaurav Raje
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sleep will sleep a thread... regardless of whether other threads exist or not. Make sure you catch the exception
 
Jay Dilla
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yea saw i could use sleep still after i posted this....my bad!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic