[concurrency-interest] Volatile / Sychronized?
brian at quiotix.com
Wed Dec 20 16:55:07 EST 2006
So long as the fields do not participate in invariants with any other
variables, and they have no state transitions where their new value
depends on their old value (counters would not pass this requirement),
Kessel, Chris wrote:
> I have various POJO's that I've just used volatile on and skipped
> synchronization, except in the few instances where 2+ fields are always
> changed at the same time.
> Wouldn't volatile be sufficient in that case? My only real concern is
> avoiding stale reads.
> -----Original Message-----
> From: concurrency-interest-bounces at cs.oswego.edu
> [mailto:concurrency-interest-bounces at cs.oswego.edu] On Behalf Of Brian
> Sent: Wednesday, December 20, 2006 1:21 PM
> To: First Last
> Cc: concurrency-interest at cs.oswego.edu
> Subject: Re: [concurrency-interest] Volatile / Sychronized?
>> Please clear up something about the proper use of volatile for me. I'm
>> having difficulty understanding when volatile is sufficent.
> I'd add to this discussion that if in doubt, steer away from volatile.
> Except for very simple cases (such as "public volatile boolean
> shutdownRequested"), it is tricky to get right.
> Concurrency-interest mailing list
> Concurrency-interest at altair.cs.oswego.edu
More information about the Concurrency-interest