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.
+     * <p>
+     * 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to