• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sleeping thread takes locks with it?

 
Timothy Chen Allen
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everybody,
I'm on the final leg before the examination, and I need some clarification: On p. 522-523 of the K&B in Chapter 9 (Threads), there is a list of points to remember on Locking and Synchronization. One of the points (on p.523) is:

If a thread goes to sleep, it takes its locks with it.

What does that mean? I think my brain is too sleep deprived to understand this (mental note: schedule some sleep...)
Thanks in advance.
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It means that Thread.sleep() does not release any locks. The thread will continue to hold all locks while sleeping.
 
Timothy Chen Allen
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ron Newman:
It means that Thread.sleep() does not release any locks. The thread will continue to hold all locks while sleeping.

Thanks Ron, that's what I was looking for.
 
Aruna Agrawal
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but why sleep doesnt release lock like wait???
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know the exact answer but some points :

1] If thread will not release lock at wait() method then how it will get notify ( how any other thread wiil call notify() on that object )


1] If suppose one thread releases lock of an object & sleeps for 1 second and another thread holds the lock , then what will happen when first thread will wake up after 1 second & need lock again ...

hope it is right .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic