| Author |
Synchronization Doubt
|
saied ims
Ranch Hand
Joined: Jun 21, 2005
Posts: 109
|
|
If two methods are synchronized in a class, only one thread can be accessing one of the two methods. In other words, once a thread acquires the lock on an object, no other thread can enter any of the synchronized methods in that class (for that object). does that Object mean the Runnable instance like class D implements Runnable{ main(){ D nr =new D(); is that mean the object? Thread r1=new Thread(nr); Thread r2=new Thread(nr)
|
 |
Barry Gaunt
Ranch Hand
Joined: Aug 03, 2002
Posts: 7729
|
|
It all depends where your synchronized methods are. If your Runnable class has a synchronized run() method, then the object used for locking is that referred to by variable nr in your example. [ November 20, 2006: Message edited by: Barry Gaunt ]
|
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
|
 |
 |
|
|
subject: Synchronization Doubt
|
|
|