File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
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://aspose.com/file-tools
 
subject: Synchronization Doubt
 
Similar Threads
Synchronized methods
Threads Again
synchronized threads
Thread behavior with synchronized method
locks and monitor