Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 76396 invoked from network); 11 Oct 2006 21:42:36 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 11 Oct 2006 21:42:36 -0000 Received: (qmail 40280 invoked by uid 500); 11 Oct 2006 21:42:34 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 40192 invoked by uid 500); 11 Oct 2006 21:42:33 -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 40181 invoked by uid 99); 11 Oct 2006 21:42:33 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 11 Oct 2006 14:42:33 -0700 X-ASF-Spam-Status: No, hits=0.5 required=10.0 tests=DNS_FROM_RFC_ABUSE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of kennethx@gmail.com designates 66.249.82.235 as permitted sender) Received: from [66.249.82.235] (HELO wx-out-0506.google.com) (66.249.82.235) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 11 Oct 2006 14:42:31 -0700 Received: by wx-out-0506.google.com with SMTP id t4so372155wxc for ; Wed, 11 Oct 2006 14:42:10 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:from:to:subject:date:message-id:mime-version:content-type:content-transfer-encoding:x-mailer:in-reply-to:x-mimeole:thread-index; b=sub0I0prTR9v80N68hVUMmGWWo0Kbm2ugz6PIYPcpKh+DXJ9I1HqEtDZoJgFMwnOj3SMPiGs2x5t1JHYIeVYRc7V32iaknY8SgK1nk13G4x0U4Ftqzt0FUnw2xY6adfbVyA+h8a39KSGNTbYA6slIJc7AR0asAIoa3/SstkaZio= Received: by 10.70.33.10 with SMTP id g10mr1475170wxg; Wed, 11 Oct 2006 14:42:09 -0700 (PDT) Received: from ThinkpadX40 ( [24.149.184.242]) by mx.google.com with ESMTP id h15sm1609037wxd.2006.10.11.14.42.08; Wed, 11 Oct 2006 14:42:09 -0700 (PDT) From: "Kenneth Xu" To: "'Jakarta Commons Developers List'" Subject: RE: Logging: SimpleLog not thread-safe Date: Wed, 11 Oct 2006 17:42:09 -0400 Message-ID: <015701c6ed7e$1c13f510$6a00a8c0@ThinkpadX40> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 11 In-Reply-To: <1160557470.5386.24.camel@blackbox> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2962 Thread-Index: AcbtFGEMfu2wvaXoQRCjREznkBpoNQAOhJQw X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Hi, I think a thread local formatter will give us better performance than creating one new in every log invocation. Just my 2 cents, Thanks, Ken -----Original Message----- From: Simon Kitching [mailto:skitching@apache.org] Sent: Wednesday, October 11, 2006 5:05 AM To: Jakarta Commons Developers List Subject: Re: Logging: SimpleLog not thread-safe Hi Martin, Thanks very much for letting us know about this. I think you're right about there being a thread-safety issue. SimpleLog is definitely in use, but obviously this bug will only be triggered under pretty rare conditions, and I expect would usually just result in a malformed date string which may not be noticed anyway. But it should be fixed; I'll try to do that this weekend. Regards, Simon On Fri, 2006-10-06 at 17:15 +0100, Martin Wilson wrote: > Hi, > > I'm not sure if anyone else uses the SimpleLog class - anyway I've > noticed that SimpleLog.log is not thread-safe. The following code > (starting on line 282): > > if(showDateTime) { > buf.append(dateFormatter.format(new Date())); > buf.append(" "); > } > > makes an unsynchronized call to dateFormatter.format. As dateFormatter > is an instance variable, and DateFormat.format is not thread-safe, this > will cause problems if more than one thread tried to log at the same > time. > > Solution: remove the dateFormatter instance variable and instantiate a > new DateFormat each time in the log method, e.g. > > DateFormat dateFormatter = null; > try { > dateFormatter = new > SimpleDateFormat(dateTimeFormat); > } > catch(IllegalArgumentException e) { > dateFormatter = new > SimpleDateFormat(DEFAULT_DATE_TIME_FORMAT); > } > > Is anyone available who could make this change? > > Thanks, > Martin > ___________ > > Martin Wilson > martinw@bright-interactive.com > > Bright Interactive: successfully delivering interactive websites and > business applications > http://www.bright-interactive.com > 0870 240 6520 > --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org