Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

synchronization - lock tracking and static vars:

 
Nigel Shrin
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Synchronization - lock tracking and static vars:

If different threads are calling the same method, but the threads and methods are in different instances of the same class, then there is no issue of locking unless they share a static variable, is that correct? The lock must work by tracking the object.instance.memberVariable?

THANKS
 
Harpreet Singh janda
Ranch Hand
Posts: 317
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whenever a Thread enters a Synchronized methods or block it always acquires lock. No matter there is a static variable or not. But the efect will only be visible untill we are not sharing something in multiple Threads.
 
Nigel Shrin
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Harpreet
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nigel Shrin wrote:SYNCHRONIZATION - lock tracking and static vars:

If different threads are calling the same method, but the threads and methods are in different instances of the same class, then there is no issue of locking unless they share a static variable, is that correct? The lock must work by tracking the object.instance.memberVariable?

THANKS


The synchronization is only for object(job), rather than the Thread(worker) or method. And static variable is not for single object, but for class.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please KeepItDown.
 
Nigel Shrin
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you Abimaran
 
Nigel Shrin
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
SYNCHRONIZATION Synchronization - lock tracking and static variables
Apologies for previous noise polution

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic