ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Charles O'Farrell" <charl...@gmail.com>
Subject Date concurrency
Date Tue, 17 Aug 2010 04:11:50 GMT
Hi Ivy Devs,

Sorry to bother you, but we've run into some annoying issues with Ivy
and concurrency (using ant parallel). For some unbelievably stupid
reason SimpleDateFormat isn't thread safe.

http://download-llnw.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html#synchronization

Please find below a patch which illustrates one possible fix. I can
imagine you might want to do something completely different, this is
more of a show of good faith. Please let me know if you need me to
raise a Bug and/or submit a different patch.

Cheers,

Charles

diff --git a/src/java/org/apache/ivy/Ivy.java b/src/java/org/apache/ivy/Ivy.java
index 3d9d8cd..608b364 100644
--- a/src/java/org/apache/ivy/Ivy.java
+++ b/src/java/org/apache/ivy/Ivy.java
@@ -24,6 +24,7 @@ import java.net.URL;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Collection;
+import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -129,8 +130,24 @@ public class Ivy {

     private static final int KILO = 1024;

-    public static final SimpleDateFormat DATE_FORMAT = new
SimpleDateFormat("yyyyMMddHHmmss");
-
+    public static final ThreadSafeDateFormat DATE_FORMAT = new
ThreadSafeDateFormat("yyyyMMddHHmmss");
+
+    public static class ThreadSafeDateFormat {
+        private final String format;
+
+        public ThreadSafeDateFormat(String format) {
+            this.format = format;
+        }
+
+        public Date parse(String date) throws ParseException {
+            return new SimpleDateFormat(format).parse(date);
+        }
+
+        public String format(Date date) {
+            return new SimpleDateFormat(format).format(date);
+        }
+    }
+
     /**
      * the current version of Ivy, as displayed on the console when
      * Ivy is initialized

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message