Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 10397 invoked from network); 19 Jan 2006 20:03:09 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 19 Jan 2006 20:03:09 -0000 Received: (qmail 55142 invoked by uid 500); 19 Jan 2006 20:03:05 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 55071 invoked by uid 500); 19 Jan 2006 20:03:05 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 55060 invoked by uid 99); 19 Jan 2006 20:03:05 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 19 Jan 2006 12:03:05 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of robertburrelldonkin@blueyonder.co.uk designates 195.188.213.4 as permitted sender) Received: from [195.188.213.4] (HELO smtp-out1.blueyonder.co.uk) (195.188.213.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 19 Jan 2006 12:03:04 -0800 Received: from knossos.elmet ([82.38.65.173]) by smtp-out1.blueyonder.co.uk with Microsoft SMTPSVC(5.0.2195.6713); Thu, 19 Jan 2006 20:03:43 +0000 Subject: Re: [logging] Log4JLogger thread safety issue From: robert burrell donkin To: Jakarta Commons Developers List In-Reply-To: <1137644260.4690.16.camel@localhost.localdomain> References: <1137622693.5323.57.camel@knossos.elmet> <1137644260.4690.16.camel@localhost.localdomain> Content-Type: text/plain Date: Thu, 19 Jan 2006 20:04:59 +0000 Message-Id: <1137701099.5095.27.camel@knossos.elmet> Mime-Version: 1.0 X-Mailer: Evolution 2.0.1-1mdk Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 19 Jan 2006 20:03:43.0459 (UTC) FILETIME=[72E20330:01C61D33] X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N On Thu, 2006-01-19 at 17:17 +1300, Simon Kitching wrote: > On Wed, 2006-01-18 at 22:18 +0000, robert burrell donkin wrote: > > on the subject of thread safety, there is a potential issue with > > Log4JLogger - take a look at getLogger(). i'd like a second opinion (and > > a third and a forth, if possible) so i'll post this now before i analyse > > it. > > > > (see > > http://mail-archives.apache.org/mod_mbox/jakarta-commons-user/200511.mbox/%3cDDDD97FE8191FA4DA8DF33EC938394630157E1F5@MSSAHQ11.corp.valero.com%3e) > > > > I don't think this is valid. Yes there is a race condition but it's > harmless. > NB: the synchronized keyword also ensures that CPU caches are correctly > synchronized. However even taking this into account I can't see a > situation where anything bad can happen. i was wondering whether a logger could be partially constructed and if so what the likely effect would be (thread A enters getLogger() and starts the construction of the logger but is not finished before thread B enters the method and finds logger has been assigned (so not null) but not completed constructed.) i'm unsure whether this scenario is allowed by the java language and virtual machine specifications. a few similarly unintuitive ones are. finding out the answer would probably require spending a good few hours analysing the specifications. i'm not sure that this is a priority for me right now (since i suspect that this would have been reported had it been a practical scenario). any volunteers? if this is a real problem then it could be fixed by assigning to a temporary variable: public Logger getLogger() { Logger logger = this.logger; if (logger == null) { logger = Logger.getLogger(name); } this.logger = logger; return (this.logger); } but it's probably best to err on the side of inertia if we aren't sure that the issue is real... - robert --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org