[concurrency-interest] Volatile / Sychronized?

Kessel, Chris ckessel at c-cor.com
Wed Dec 20 16:31:56 EST 2006


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
Goetz
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
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest




More information about the Concurrency-interest mailing list