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

Ryan LeCompte ryan.lecompte at pangonetworks.com
Fri Oct 14 09:56:55 EDT 2005


Hello all,

 

I know that there really isn't a need to do this, but I was wondering if the
following code snippet would be "safe" - ie, no deadlocks.

 

class Test {

   private volatile boolean value = false;

 

    synchronized void someOperation() {

        // do something with "value"

     }

}

 

In other words, there is no harm in using a volatile variable in a
synchronized method or block, right?

 

Thanks,

Ryan

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20051014/d77a4a80/attachment.htm


More information about the Concurrency-interest mailing list