• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Thread synchronization

 
Ranch Hand
Posts: 72
MySQL Database AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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??
 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 72
MySQL Database AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Whizlabs Java Support
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 72
MySQL Database AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
welcome shashank
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic