[concurrency-interest] Basic thread safety question: final/volatile/synchronized fields
ckessel at c-cor.com
Wed Dec 20 12:35:17 EST 2006
Having read JCiP, I find I'm quite paranoid now about thread safety :).
This is a good thing, but it leads me to a question just to make sure I
understand something basic.
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?
The default in a lot of code, and my default for years, has been to
declare object fields "private Foo _f;" in objects that end up being
used in multi-threaded contexts. Based on my understanding now, that
can't be a thread-safe field (unless used in synchronized blocks).
More information about the Concurrency-interest