jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1590123 - /jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ISO8601.java
Date Fri, 25 Apr 2014 19:59:15 GMT
Author: jukka
Date: Fri Apr 25 19:59:15 2014
New Revision: 1590123

URL: http://svn.apache.org/r1590123
Log:
JCR-3775: Avoid lock contention in ISO8601.parse()

Only call getTimeZone() on non-GMT time zones.

Modified:
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ISO8601.java

Modified: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ISO8601.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ISO8601.java?rev=1590123&r1=1590122&r2=1590123&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ISO8601.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ISO8601.java
Fri Apr 25 19:59:15 2014
@@ -46,6 +46,9 @@ import java.util.TimeZone;
  * </pre>
  */
 public final class ISO8601 {
+
+    private static final TimeZone GMT = TimeZone.getTimeZone("GMT");
+
     /**
      * Parses an ISO8601-compliant date/time string.
      *
@@ -82,7 +85,7 @@ public final class ISO8601 {
          */
 
         int year, month, day, hour, min, sec, ms;
-        String tzID;
+        TimeZone tz;
         try {
             // year (YYYY)
             year = Integer.parseInt(text.substring(start, start + 4));
@@ -136,14 +139,18 @@ public final class ISO8601 {
             ms = Integer.parseInt(text.substring(start, start + 3));
             start += 3;
             // time zone designator (Z or +00:00 or -00:00)
-            if (text.charAt(start) == '+' || text.charAt(start) == '-') {
-                // offset to UTC specified in the format +00:00/-00:00
-                tzID = "GMT" + text.substring(start);
-            } else if (text.substring(start).equals("Z")) {
-                tzID = "GMT";
+            String tzid = text.substring(start);
+            if (tzid.equals("Z")) {
+                tz = GMT;
             } else {
-                // invalid time zone designator
-                return null;
+                // offset to UTC specified in the format +00:00/-00:00
+                tzid = "GMT" + tzid;
+                tz = TimeZone.getTimeZone(tzid);
+                // verify id of returned time zone (getTimeZone defaults to "GMT")
+                if (!tz.getID().equals(tzid)) {
+                    // invalid time zone
+                    return null;
+                }
             }
         } catch (IndexOutOfBoundsException e) {
             return null;
@@ -151,13 +158,6 @@ public final class ISO8601 {
             return null;
         }
 
-        TimeZone tz = TimeZone.getTimeZone(tzID);
-        // verify id of returned time zone (getTimeZone defaults to "GMT")
-        if (!tz.getID().equals(tzID)) {
-            // invalid time zone
-            return null;
-        }
-
         // initialize Calendar object
         Calendar cal = Calendar.getInstance(tz);
         cal.setLenient(false);



Mime
View raw message