• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread synchronization

 
shashank dwivedi
Ranch Hand
Posts: 65
AngularJS Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 65
AngularJS Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65
AngularJS Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
welcome shashank
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic