[concurrency-interest] Basic thread safety question: final/volatile/synchronized fields
joe.bowbeer at gmail.com
Wed Dec 20 17:32:45 EST 2006
On 12/20/06, Kessel, Chris <ckessel at c-cor.com> wrote:
> Is it correct to say that a thread safe class requires (though this is
> not necessarily sufficient) that every instance field be final,
> volatile, or accessed in synchronized blocks?
For objects that are not changed after they are constructed, "safe
publication" is sufficient.
Objects that are not changed after they are constructed come in two
flavors: those that can't be changed (aka immutable) and those that
could be changed but aren't (aka "effectively immutable").
Safe publication means transmitting the object to another thread by
means of a shared lock or volatile (that is, a "happens before"
Passing an object through a thread-safe queue is a common means of
More information about the Concurrency-interest