This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

difference between wait() and sleep()  RSS feed

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

what is the difference between wait() and sleep() in threads.
 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
both methods make the thread into waiting state. but the difference is that on call of wait() the thread releases the lock on the object it has acquired whereas sleep() doesnt do.
 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another difference is that a thread executing the Thread.sleep method cannot
be awaken, whereas a thread executing the Object.wait() can be awaken by
another thread invoking the Object.notify() method.
On the other hand, both methods can throw an InterruptedException is the thread executing the method is interrupted.

Gilles
 
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perfect..
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The main difference between two method is that sleep is a static method of class Thread and wait is method in Object class

Thread.sleep()
wait() non static method in Object class
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by kiran peruka:
Hi,

what is the difference between wait() and sleep() in threads.



One more and main difference between wait() and sleep() is that wait() can be only used from synchronized block and main purpose of wait() is inter thread
communication.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!