Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 51413 invoked from network); 19 Jan 2006 04:17:39 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 19 Jan 2006 04:17:39 -0000 Received: (qmail 33595 invoked by uid 500); 19 Jan 2006 04:17:36 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 33518 invoked by uid 500); 19 Jan 2006 04:17:35 -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 33507 invoked by uid 99); 19 Jan 2006 04:17:35 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 Jan 2006 20:17:35 -0800 X-ASF-Spam-Status: No, hits=0.8 required=10.0 tests=INFO_TLD X-Spam-Check-By: apache.org Received-SPF: neutral (asf.osuosl.org: local policy) Received: from [210.86.15.147] (HELO mta204-rme.xtra.co.nz) (210.86.15.147) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 Jan 2006 20:17:34 -0800 Received: from mta4-rme.xtra.co.nz ([210.86.15.193]) by mta204-rme.xtra.co.nz with ESMTP id <20060119041712.DOKP10467.mta204-rme.xtra.co.nz@mta4-rme.xtra.co.nz> for ; Thu, 19 Jan 2006 17:17:12 +1300 Received: from [10.1.1.6] ([222.153.144.217]) by mta4-rme.xtra.co.nz with ESMTP id <20060119041712.SZMM1416.mta4-rme.xtra.co.nz@[10.1.1.6]> for ; Thu, 19 Jan 2006 17:17:12 +1300 Subject: Re: [logging] Log4JLogger thread safety issue From: Simon Kitching Reply-To: skitching@apache.org To: Jakarta Commons Developers List In-Reply-To: <1137622693.5323.57.camel@knossos.elmet> References: <1137622693.5323.57.camel@knossos.elmet> Content-Type: text/plain Date: Thu, 19 Jan 2006 17:17:40 +1300 Message-Id: <1137644260.4690.16.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.0.4 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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. === Scenario begins === A Log instance "log" is deserialized Thread A calls log.info("infomsg"). There's no log object so one is fetched from log4j; object X is returned. Thread B calls log.warn("warnmsg"). There's no log object so one is fetched from log4j; object X is returned again. One of A or B updates the Log4JLogger.logger member to point to X. The other then stomps over this value - with a reference to exactly the same object. A and B then call the info and warn methods on object X. Because X is thread-safe, this works fine. === Scenario ends === I can't see any problem here.... 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. Regards, Simon --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org