• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

sleep/wait and locks

 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know that when a thread calls wait(object), it will release the lock on object until it is notified.

Why is it when a thread goes to sleep, it doesn't release its' locks?
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rachel Glenn wrote:I know that when a thread calls wait(object), it will release the lock on object until it is notified.

Why is it when a thread goes to sleep, it doesn't release its' locks?



Thread.sleep(n) is a static method, and it is not called on an object, so it does not have lock or monitor to release.
 
Rachel Glenn
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you..makes sense..because it is the Thread class itself (via the static sleep() method call) that puts the thread instance to sleep, and therefore does not handle the locks.

But with wait(), that is called on another object instance....so it can release the lock.
reply
    Bookmark Topic Watch Topic
  • New Topic