| Author |
Thread.sleep() does not release lock?
|
Chandra Bhatt
Ranch Hand
Joined: Feb 28, 2007
Posts: 1707
|
|
Output: Woke up from sleep Woke up from sleep Woke up from sleep Woke up from sleep Woke up from sleep Woke up from sleep Woke up from sleep Woke up from sleep Woke up from sleep Woke up from sleep sum = 50 Does this example demonstrate the fact "Thread.sleep(...) does not release the lock"? Kindly suggest! Thanks, cmbhatt [ April 24, 2007: Message edited by: Chandra Bhatt ]
|
cmbhatt
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16680
|
|
Does this example demonstrate the fact "Thread.sleep(...) does not release the lock"?
The Thread.sleep() method does not release any locks. Where did you read/heard that it did? Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Chandra Bhatt
Ranch Hand
Joined: Feb 28, 2007
Posts: 1707
|
|
Thanks Henry,
The Thread.sleep() method does not release any locks. Where did you read/heard that it did?
Nay, I only read/heard the original one "does not release...". Actually I supposed to see what exactly happens in case if an object is notified from within a loop where we call to the sleep(...) method inside the sync block. Anyways thank for your reply! Regards, cmbhatt
|
 |
swarna dasa
Ranch Hand
Joined: Mar 15, 2007
Posts: 108
|
|
I don't get this I thought the output would be 50. Though the demothread calls notify it doesn't leave the synchronized context till i=50, so the main thread cannot print the sum, as it occurs in the synchronized context. What am i failing to understand?
|
 |
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
|
|
Originally posted by swarna dasa: ... I thought the output would be 50...
As posted, the output should be 50. I'm guessing this code was altered to get more "manageable" output. ...while(++i<=10)...
|
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
|
 |
 |
|
|
subject: Thread.sleep() does not release lock?
|
|
|