Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: Lew Newsgroups: comp.lang.java.programmer Subject: Re: Question whether a problem with race conditions exists in this case Date: Wed, 14 Dec 2011 10:44:12 -0800 (PST) Organization: http://groups.google.com Lines: 19 Message-ID: <8946607.360.1323888252717.JavaMail.geo-discussion-forums@prfb7> References: <8bbbbee3-adcc-4f28-aff5-2e230b047401@u6g2000vbg.googlegroups.com> Reply-To: comp.lang.java.programmer@googlegroups.com NNTP-Posting-Host: 173.164.137.214 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1323888253 18723 127.0.0.1 (14 Dec 2011 18:44:13 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 14 Dec 2011 18:44:13 +0000 (UTC) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=173.164.137.214; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T User-Agent: G2/1.0 X-Google-Web-Client: true Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:10734 On Wednesday, December 14, 2011 9:53:37 AM UTC-8, Andreas Leitgeb wrote: > Saxo wrote: > > public class Node { > > AtomicBoolean useNewValue = new AtomicBoolean(false); > > private Object newValue = null; > > private Object previousValue = null; > > private Object lock = new Object(); > > I think, you would at least have to declare these volatile. Nope, they use 'synchronized'. 'volatile' wouldn't work anyway, because these have to change together, so they must use 'synchronized'. > Otherwise, a different thread might e.g. still see an old > value in newValue, after the AtomicBoolean's value changes > to true. -- Lew