wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Thread synchronization 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 "Thread synchronization" Watch "Thread synchronization" New topic
Author

Thread synchronization

shashank dwivedi
Ranch Hand

Joined: Mar 06, 2012
Posts: 61


suppose we have two threads t1 and t2.
t1 is accessing static synchronized method of A.
can t2 access simultaneously static synchronized method of B??
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1761
    
    7

Yes, because the methods are defined in different classes they synchronize on different locks. Had they been defined in a single class, then no.


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
shashank dwivedi
Ranch Hand

Joined: Mar 06, 2012
Posts: 61
Jelle Klap wrote:Yes, because the methods are defined in different classes they synchronize on different locks. Had they been defined in a single class, then no.

shashank dwivedi wrote: Thanks Jelle for clarification
James X Peterson
Whizlabs Java Support
Ranch Hand

Joined: Feb 26, 2013
Posts: 158
Hi shashank dwivedi,

As the methods are defined in different classes the locks will be different. The synchronization will depend on the object for the class you initialized. If you are accessing a method of a class that is synchronized using obj1 object then obj2 object of that class cannot access same synchronized method.


Regards,
James
shashank dwivedi
Ranch Hand

Joined: Mar 06, 2012
Posts: 61
James Peterson wrote:Hi shashank dwivedi,

As the methods are defined in different classes the locks will be different. The synchronization will depend on the object for the class you initialized. If you are accessing a method of a class that is synchronized using obj1 object then obj2 object of that class cannot access same synchronized method.


Regards,
James

Shashank Dwivedi wrote:Thanks James
James X Peterson
Whizlabs Java Support
Ranch Hand

Joined: Feb 26, 2013
Posts: 158
welcome shashank
 
 
subject: Thread synchronization