wood burning stoves*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes synchronization - lock tracking and static vars: Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "synchronization - lock tracking and static vars:" Watch "synchronization - lock tracking and static vars:" New topic
Author

synchronization - lock tracking and static vars:

Nigel Shrin
Ranch Hand

Joined: May 18, 2009
Posts: 137
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


Nigel
Harpreet Singh janda
Ranch Hand

Joined: Jan 14, 2010
Posts: 317

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

Joined: May 18, 2009
Posts: 137
Thank you Harpreet
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

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.


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60071
    
  65

Please KeepItDown.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Nigel Shrin
Ranch Hand

Joined: May 18, 2009
Posts: 137
thank you Abimaran
Nigel Shrin
Ranch Hand

Joined: May 18, 2009
Posts: 137
SYNCHRONIZATION Synchronization - lock tracking and static variables
Apologies for previous noise polution

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: synchronization - lock tracking and static vars:
 
Similar Threads
Synchronization
Whiz Lab MOCK Quesitions on THREADS
Static deadlock analysis
Synchronization block
synchronized run method.