File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sleep/wait and locks

 
Rachel Glenn
Ranch Hand
Posts: 95
  • 0
  • Mark post as helpful
  • send pies
  • 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?
 
Zhenyi Luo
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic