You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rp...@apache.org on 2017/02/02 16:20:31 UTC

logging-log4j2 git commit: LOG4J2-1805 Fixed rare race condition in FixedDateFormat, made FixedDateFormat::millisSinceMidnight method public.

Repository: logging-log4j2
Updated Branches:
  refs/heads/master 8ce7dbcdf -> d52ce48f7


LOG4J2-1805 Fixed rare race condition in FixedDateFormat, made FixedDateFormat::millisSinceMidnight method public.


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/d52ce48f
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/d52ce48f
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/d52ce48f

Branch: refs/heads/master
Commit: d52ce48f74f6abc7f210122788af90a7526bc5ef
Parents: 8ce7dbc
Author: rpopma <rp...@apache.org>
Authored: Fri Feb 3 01:20:20 2017 +0900
Committer: rpopma <rp...@apache.org>
Committed: Fri Feb 3 01:20:20 2017 +0900

----------------------------------------------------------------------
 .../core/util/datetime/FixedDateFormat.java     | 29 ++++++++++++++------
 src/changes/changes.xml                         |  3 ++
 2 files changed, 23 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d52ce48f/log4j-core/src/main/java/org/apache/logging/log4j/core/util/datetime/FixedDateFormat.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/datetime/FixedDateFormat.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/datetime/FixedDateFormat.java
index d982dea..cfb867f 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/datetime/FixedDateFormat.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/datetime/FixedDateFormat.java
@@ -281,21 +281,32 @@ public class FixedDateFormat {
         return timeZone;
     }
 
+    /**
+     * <p>Returns the number of milliseconds since midnight in the time zone that this {@code FixedDateFormat}
+     * was constructed with for the specified currentTime.</p>
+     * <p>As a side effect, this method updates the cached formatted date and the cached date demarcation timestamps
+     * when the specified current time is outside the previously set demarcation timestamps for the start or end
+     * of the current day.</p>
+     * @param currentTime the current time in millis since the epoch
+     * @return the number of milliseconds since midnight for the specified time
+     */
     // Profiling showed this method is important to log4j performance. Modify with care!
     // 30 bytes (allows immediate JVM inlining: <= -XX:MaxInlineSize=35 bytes)
-    private long millisSinceMidnight(final long now) {
-        if (now >= midnightTomorrow || now < midnightToday) {
-            updateMidnightMillis(now);
+    public long millisSinceMidnight(final long currentTime) {
+        if (currentTime >= midnightTomorrow || currentTime < midnightToday) {
+            updateMidnightMillis(currentTime);
         }
-        return now - midnightToday;
+        return currentTime - midnightToday;
     }
 
     private void updateMidnightMillis(final long now) {
-
-        updateCachedDate(now);
-
-        midnightToday = calcMidnightMillis(now, 0);
-        midnightTomorrow = calcMidnightMillis(now, 1);
+        if (now >= midnightTomorrow || now < midnightToday) {
+            synchronized (this) {
+                updateCachedDate(now);
+                midnightToday = calcMidnightMillis(now, 0);
+                midnightTomorrow = calcMidnightMillis(now, 1);
+            }
+        }
     }
 
     private long calcMidnightMillis(final long time, final int addDays) {

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d52ce48f/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index a0acffb..d32bd46 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -31,6 +31,9 @@
       <action issue="LOG4J2-1800" dev="mikes" type="fix" due-to="Vincent Tieleman">
         Report errors when sending to Kafka when using syncSend=false.
       </action>
+      <action issue="LOG4J2-1805" dev="rpopma" type="fix">
+        Fixed rare race condition in FixedDateFormat, made FixedDateFormat::millisSinceMidnight method public.
+      </action>
     </release>
     <release version="2.8" date="2017-01-21" description="GA Release 2.8">
       <action issue="LOG4J2-1780" dev="mikes" type="fix">