aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Synchronization Doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Synchronization Doubt" Watch "Synchronization Doubt" New topic
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.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Synchronization Doubt
 
Similar Threads
locks and monitor
Synchronized methods
Thread behavior with synchronized method
synchronized threads
Threads Again