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>
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 @@
                 }
             }
 
-            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()) {
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 @@
 
 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 @@
 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";