Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 28532 invoked from network); 15 Oct 2006 03:11:46 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 15 Oct 2006 03:11:45 -0000 Received: (qmail 24702 invoked by uid 500); 15 Oct 2006 03:11:44 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 24618 invoked by uid 500); 15 Oct 2006 03:11:43 -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 24607 invoked by uid 500); 15 Oct 2006 03:11:43 -0000 Received: (qmail 24604 invoked by uid 99); 15 Oct 2006 03:11:43 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 14 Oct 2006 20:11:43 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [140.211.166.113] (HELO eris.apache.org) (140.211.166.113) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 14 Oct 2006 20:11:43 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id ACD891A981A; Sat, 14 Oct 2006 20:11:20 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r464108 - /jakarta/commons/proper/logging/trunk/src/java/org/apache/commons/logging/impl/SimpleLog.java Date: Sun, 15 Oct 2006 03:11:20 -0000 To: commons-cvs@jakarta.apache.org From: skitching@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20061015031120.ACD891A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: skitching Date: Sat Oct 14 20:11:19 2006 New Revision: 464108 URL: http://svn.apache.org/viewvc?view=rev&rev=464108 Log: Fix thread-safety bug (SimpleDateFormat.format is not thread-safe). Thanks to Martin Wilson of bright-interactive for the bug report. Modified: jakarta/commons/proper/logging/trunk/src/java/org/apache/commons/logging/impl/SimpleLog.java Modified: jakarta/commons/proper/logging/trunk/src/java/org/apache/commons/logging/impl/SimpleLog.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/logging/trunk/src/java/org/apache/commons/logging/impl/SimpleLog.java?view=diff&rev=464108&r1=464107&r2=464108 ============================================================================== --- jakarta/commons/proper/logging/trunk/src/java/org/apache/commons/logging/impl/SimpleLog.java (original) +++ jakarta/commons/proper/logging/trunk/src/java/org/apache/commons/logging/impl/SimpleLog.java Sat Oct 14 20:11:19 2006 @@ -100,7 +100,15 @@ static protected boolean showDateTime = false; /** The date and time format to use in the log message */ static protected String dateTimeFormat = DEFAULT_DATE_TIME_FORMAT; - /** Used to format times */ + + /** + * Used to format times. + *

+ * Any code that accesses this object should first obtain a lock on it, + * ie use synchronized(dateFormatter); this requirement was introduced + * in 1.1.1 to fix an existing thread safety bug (SimpleDateFormat.format + * is not thread-safe). + */ static protected DateFormat dateFormatter = null; // ---------------------------------------------------- Log Level Constants @@ -179,7 +187,6 @@ } } - // ------------------------------------------------------------- Attributes /** The name of this simple log instance */ @@ -281,7 +288,12 @@ // Append date-time if so configured if(showDateTime) { - buf.append(dateFormatter.format(new Date())); + Date now = new Date(); + String dateText; + synchronized(dateFormatter) { + dateText = dateFormatter.format(now); + } + buf.append(dateText); buf.append(" "); } --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org