[concurrency-interest] Class variables and concurrency
dawidk at mathcs.emory.edu
Sun Nov 6 21:20:21 EST 2005
David Holmes wrote:
>>Dawid Kurzyniec writes:
>>Now, I was responding to your fix: for it to be 100% correct, you need
>>that "final". To my understanding (experts correct me if I'm wrong), you
>>may otherwise see this field uninitialized (i.e. null) in some threads.
>You will never see a static final field with its default initialized value.
>The synchronization that occurs as part of the class initialization process
>make this impossible. The lock of the Class object is held during static
>initialization of the class, and any use of the class that requires that it
>be initialized also must acquire that lock. So no thread can use the class
>without having gained the lock, which is only released after initialization
>is complete. The release of the lock by the initializing thread (and thus
>all initialization code) happens-before the lock acquisition by another
Is the same guaranteed if the field is non-final?
Does this mean that every access to any class variable involves locking?
Or is there some kind of a thread-local cache so that each thread locks
on any class at most once? What does the specification say about it?
More information about the Concurrency-interest