| Author |
Threads-Can someone reply to this que?
|
sanjana narayanan
Ranch Hand
Joined: Nov 25, 2003
Posts: 142
|
|
Hi, In threads, what is the purpose of getting multiple locks on the same object by the same thread. Eg: public void run() { Synchronized(this)// lock is obtained on 'this' object { Synchronized(this) //#2 lock is agin obtained on the 'this' obj { -------------- On obtaining the first lock, the thread holds the lock on the object and prevents any other thread from getting a lock on the 'this' object. so when do we go for the #2 lock. -Sanjana [ December 25, 2003: Message edited by: sanjana narayanan ]
|
 |
Marlene Miller
Ranch Hand
Joined: Mar 05, 2003
Posts: 1391
|
|
Hi Sanjana, When I read about a thread executing more than one block of synchronized code, I think of synchronized methods being invoked in succession or recursively. Both methods are synchronized, because m2 might be invoked without invoking m1 first. Note: I changed the words to correct the error Vad found [ December 25, 2003: Message edited by: Marlene Miller ]
|
 |
Vad Fogel
Ranch Hand
Joined: Aug 25, 2003
Posts: 504
|
|
Originally posted by Marlene Miller: When I read about threads having multiple locks on an object, I think of a different kind of example than yours.
Multiple locks on the same object?? Hmm, doesn't any object have only one lock that becomes a subject of multithreaded contest?
|
 |
Marlene Miller
Ranch Hand
Joined: Mar 05, 2003
Posts: 1391
|
|
Thank you Vad. You are correct, I am wrong. An object has a lock. A thread acquires the lock of the object. I should have said a thread performs multiple lock actions on an object.
|
 |
 |
|
|
subject: Threads-Can someone reply to this que?
|
|
|