[rhq] Branch 'feature/hadoop-plugin' - modules/core

lkrejci lkrejci at fedoraproject.org
Mon Aug 6 18:48:35 UTC 2012


 modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/event/log/Log4JLogEntryProcessor.java |   16 ++++++----
 1 file changed, 10 insertions(+), 6 deletions(-)

New commits:
commit f719aa14b69abda856fe51e1d45db3f9b7588c85
Author: Lukas Krejci <lkrejci at redhat.com>
Date:   Mon Aug 6 20:48:13 2012 +0200

    Make the date formats used by the log4j log processor instance fields so
    that they are not shared by multiple instances that would use those formats
    from different threads.
    The DateFormat is not a thread safe class.

diff --git a/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/event/log/Log4JLogEntryProcessor.java b/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/event/log/Log4JLogEntryProcessor.java
index 9eb4f09..7cfb3cf 100644
--- a/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/event/log/Log4JLogEntryProcessor.java
+++ b/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/event/log/Log4JLogEntryProcessor.java
@@ -53,12 +53,16 @@ public class Log4JLogEntryProcessor extends MultiLineLogEntryProcessor {
     private static final String REGEX;
     private static final Pattern PATTERN;
 
+    //note that the DateFormat instances are INTENTIONALLY instance fields.
+    //DateFormats are not thread safe and because we can have multiple log processors
+    //each processing its log file in a separate thread, we'd get formatting errors
+    //where there weren't any...
     private static final String ISO8601_DATE_PATTERN = "yyyy-MM-dd kk:mm:ss,SSS";
-    private static final DateFormat ISO8601_DATE_FORMAT = new SimpleDateFormat(ISO8601_DATE_PATTERN);
+    private final DateFormat iso8601DateFormat = new SimpleDateFormat(ISO8601_DATE_PATTERN);
     private static final String ABSOLUTE_DATE_PATTERN = "kk:mm:ss,SSS";
-    private static final DateFormat ABSOLUTE_DATE_FORMAT = new SimpleDateFormat(ABSOLUTE_DATE_PATTERN);
+    private final DateFormat absoluteDateFormat = new SimpleDateFormat(ABSOLUTE_DATE_PATTERN);
     private static final String DATE_DATE_PATTERN = "dd MMM yyyy kk:mm:ss,SSS";
-    private static final DateFormat DATE_DATE_FORMAT = new SimpleDateFormat(DATE_DATE_PATTERN);
+    private final DateFormat dateDateFormat = new SimpleDateFormat(DATE_DATE_PATTERN);
 
     private static final Map<Priority, EventSeverity> PRIORITY_TO_SEVERITY_MAP = new LinkedHashMap<Priority, EventSeverity>();
 
@@ -101,7 +105,7 @@ public class Log4JLogEntryProcessor extends MultiLineLogEntryProcessor {
     }
 
     protected DateFormat getDefaultDateFormat() {
-        return ISO8601_DATE_FORMAT;
+        return iso8601DateFormat;
     }
 
     protected Date parseDateString(String dateString) throws ParseException {
@@ -110,10 +114,10 @@ public class Log4JLogEntryProcessor extends MultiLineLogEntryProcessor {
             timestamp = super.parseDateString(dateString);
         } catch (ParseException e) {
             try {
-                timestamp = DATE_DATE_FORMAT.parse(dateString);
+                timestamp = dateDateFormat.parse(dateString);
             } catch (java.text.ParseException e1) {
                 try {
-                    timestamp = ABSOLUTE_DATE_FORMAT.parse(dateString);
+                    timestamp = absoluteDateFormat.parse(dateString);
                 } catch (java.text.ParseException e2) {
                     throw new ParseException("Unable to parse date '" + dateString
                         + "' using either ISO8601, DATE, or ABSOLUTE date formats. Please specify a date format.");




More information about the rhq-commits mailing list