You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sk...@apache.org on 2006/10/15 05:11:20 UTC
svn commit: r464108 -
/jakarta/commons/proper/logging/trunk/src/java/org/apache/commons/logging/impl/SimpleLog.java
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: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org