[concurrency-interest] Mixing volatile and synchronized together...

Ryan LeCompte ryan.lecompte at pangonetworks.com
Fri Oct 14 12:56:06 EDT 2005


Great. I just wanted to be clear on the behavior. So it's okay then to use a
volatile variable in a synchronized method/block as well as an
unsynchronized method/block in the same class?

Thanks,
Ryan

-----Original Message-----
From: Tim Peierls [mailto:tim at peierls.net] 
Sent: Friday, October 14, 2005 11:38 AM
To: Ryan LeCompte
Cc: concurrency-interest at altair.cs.oswego.edu
Subject: Re: [concurrency-interest] Mixing volatile and synchronized
together...

Ryan LeCompte wrote:
> I know that there really isn't a need to do this, but I was wondering if 
> In other words, there is no harm in using a volatile variable in a 
> synchronized method or block, right?

Right, no harm. Depending on the situation, one or the other might be
superfluous, but there is 
nothing unsafe about accessing a volatile in a synchronized block or method.

--tim



More information about the Concurrency-interest mailing list