Win a copy of Learn Spring Security (video course) this week in the Spring forum!
    Bookmark Topic Watch Topic
  • New Topic

is thread.sleep safe?

 
Azrael Noor
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
  • Report post to moderator
is thread.sleep safe if used in while(true) loop?
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Report post to moderator
How do you mean safe? Your computer won't blow up if you use it like that. So yea in that way it is safe.
 
Azrael Noor
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
  • Report post to moderator


but my computer once gone in loop is not allowing to stop the execution of application. Because i used Thread.Sleep in Loop.
 
Matthew Brown
Bartender
Posts: 4565
8
  • Mark post as helpful
  • send pies
  • Report post to moderator
Doesn't that sound like the while(true) is more likely to be a problem than Thread.sleep()? If you're going to go into a loop, make sure there's a way out of it.
 
Chris Hurst
Ranch Hand
Posts: 443
3
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Report post to moderator
What you doing about InterruptedException handling ...

presumably your logic should be catch InterruptedException determine application stop is required and break out of loop.
How are you triggering, signalling stop ??

You could make the thread your sleeping in a daemon thread , depends on what its purpose is.

We need some code really ;-)
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Report post to moderator
I should probably mention (though Azrael Noor you should really have said this too) this is a cross post and the code in question is a Servlet. Please continue the discussion here.
 
    Bookmark Topic Watch Topic
  • New Topic