Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Implementing sleep() like funtionality in a non threaded class

 
Jay Dilla
Ranch Hand
Posts: 201
  • 0
  • 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: 4549
8
Java Netbeans IDE Scala
  • 0
  • 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
  • 0
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yea saw i could use sleep still after i posted this....my bad!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic