• Post Reply Bookmark Topic Watch Topic
  • New Topic

Thread.sleep

 
Shaan Shar
Ranch Hand
Posts: 1249
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I have a query I am using a custom class which is neither implementing Runnable Interface nor extending Thread Class. But still I want to use Thread.sleep function which is a static function. Now the confusion is whether is it a good practice that we can use sleep method anywhere although that class is not a thread. Please suggest me is this is not a performance issue. :roll:
 
Vlado Zajac
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is OK to use Thred.sleep() outside of Thread or Runnable, any Java code runs inside a thread. If waiting some time is what you want, Thread.sleep() is good way to do it.

No problem with preformance. But you should not sleep (or do something time-consuming) in an (AWT) event handler because it will block processing of other events.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!