This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Synchronization Doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Synchronization Doubt" Watch "Synchronization Doubt" New topic

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

class D implements Runnable{

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.
wood burning stoves
subject: Synchronization Doubt
It's not a secret anymore!