asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From buyin...@apache.org
Subject asterixdb git commit: SimpleDateFormat Is Not Thread Safe
Date Sun, 14 May 2017 03:11:46 GMT
Repository: asterixdb
Updated Branches:
  refs/heads/master df01a852d -> 79416558d


SimpleDateFormat Is Not Thread Safe

Guard SimpleDateFormat with a ThreadLocal.

Fixes integration test hang observed in:

https://asterix-jenkins.ics.uci.edu/job/asterix-gerrit-integration-tests/2772/console

 - java.lang.ArrayIndexOutOfBoundsException: 960
	at sun.util.calendar.BaseCalendar.getCalendarDateFromFixedDate(BaseCalendar.java:453)
	at java.util.GregorianCalendar.computeFields(GregorianCalendar.java:2397)
	at java.util.GregorianCalendar.computeFields(GregorianCalendar.java:2312)
	at java.util.Calendar.setTimeInMillis(Calendar.java:1804)
	at java.util.Calendar.setTime(Calendar.java:1770)
	at java.text.SimpleDateFormat.format(SimpleDateFormat.java:943)
	at java.text.SimpleDateFormat.format(SimpleDateFormat.java:936)
	at java.text.DateFormat.format(DateFormat.java:345)
	at org.apache.asterix.event.management.EventTask.run(EventTask.java:118)
	at java.util.TimerThread.mainLoop(Timer.java:555)
	at java.util.TimerThread.run(Timer.java:505)

Change-Id: I4e057e893269b71b157b154721d2de1fe1f8c020
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1740
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Till Westmann <tillw@apache.org>


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

Branch: refs/heads/master
Commit: 79416558dd37615279443371f7eb25930273a14d
Parents: df01a85
Author: Michael Blow <mblow@apache.org>
Authored: Fri May 12 14:15:04 2017 -0400
Committer: Yingyi Bu <buyingyi@gmail.com>
Committed: Sat May 13 20:11:25 2017 -0700

----------------------------------------------------------------------
 .../main/java/org/apache/asterix/event/management/EventTask.java | 2 +-
 .../main/java/org/apache/asterix/event/management/EventUtil.java | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/79416558/asterixdb/asterix-events/src/main/java/org/apache/asterix/event/management/EventTask.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-events/src/main/java/org/apache/asterix/event/management/EventTask.java
b/asterixdb/asterix-events/src/main/java/org/apache/asterix/event/management/EventTask.java
index 29b855d..afd53de 100644
--- a/asterixdb/asterix-events/src/main/java/org/apache/asterix/event/management/EventTask.java
+++ b/asterixdb/asterix-events/src/main/java/org/apache/asterix/event/management/EventTask.java
@@ -115,7 +115,7 @@ public class EventTask extends TimerTask {
                 }
             }
 
-            logger.debug(EventUtil.dateFormat.format(new Date()) + " " + "EVENT "
+            logger.debug(EventUtil.dateFormat.get().format(new Date()) + " " + "EVENT "
                     + pattern.getEvent().getType().toUpperCase() + " at " + location.getId().toUpperCase());
             try {
                 if (!client.isDryRun()) {

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/79416558/asterixdb/asterix-events/src/main/java/org/apache/asterix/event/management/EventUtil.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-events/src/main/java/org/apache/asterix/event/management/EventUtil.java
b/asterixdb/asterix-events/src/main/java/org/apache/asterix/event/management/EventUtil.java
index 55e0780..4dc3124 100644
--- a/asterixdb/asterix-events/src/main/java/org/apache/asterix/event/management/EventUtil.java
+++ b/asterixdb/asterix-events/src/main/java/org/apache/asterix/event/management/EventUtil.java
@@ -20,7 +20,6 @@ package org.apache.asterix.event.management;
 
 import java.io.File;
 import java.io.IOException;
-import java.math.BigInteger;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
@@ -41,7 +40,8 @@ import org.apache.asterix.event.schema.pattern.Pattern;
 public class EventUtil {
 
     public static final String EVENTS_DIR = "events";
-    public static final DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
+    public static final ThreadLocal<DateFormat> dateFormat =
+            ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"));
     public static final String NC_JAVA_OPTS = "nc.java.opts";
     public static final String CC_JAVA_OPTS = "cc.java.opts";
 


Mime
View raw message