[concurrency-interest] Basic thread safety question: final/volatile/synchronized fields

Kessel, Chris ckessel at c-cor.com
Wed Dec 20 13:08:50 EST 2006


The "private" has nothing to do with it. It's just a common default
declaration for instance fields.  I didn't mean to imply it had anything
to do with threading.

The question was in the first part really.  Must a thread safe class
have every instance field protected by volatile, final, or synchronized
blocks?

-----Original Message-----
From: Jeremy Manson [mailto:jmanson at cs.umd.edu] 
Sent: Wednesday, December 20, 2006 10:05 AM
To: Kessel, Chris
Cc: concurrency-interest at cs.oswego.edu
Subject: Re: [concurrency-interest] Basic thread safety question:
final/volatile/synchronized fields

Kessel, Chris wrote:

> 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).
> 

This is a misconception I have never heard, so I'm thinking there must 
be more to it.  A private qualifier has no effect on threading 
whatsoever.  All it means is that (coarsely) you can't access that field

directly from outside the object.

"Thread-safe" being something of an imprecise term, what effect did you 
think it had on threading?

					Jeremy




More information about the Concurrency-interest mailing list