Author: dkuleshov
Date: 2011-09-06 05:43:03 -0400 (Tue, 06 Sep 2011)
New Revision: 4868
Modified:
kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/ISO8601ASF.java
kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/Tools.java
Log:
EXOJCR-1518: provided an Util method to give an alternative to TimeZone.getTimeZone with
less contention
Modified:
kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/ISO8601ASF.java
===================================================================
---
kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/ISO8601ASF.java 2011-09-06
09:24:05 UTC (rev 4867)
+++
kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/ISO8601ASF.java 2011-09-06
09:43:03 UTC (rev 4868)
@@ -187,7 +187,7 @@
return null;
}
- TimeZone tz = TimeZone.getTimeZone(tzID);
+ TimeZone tz = Tools.getTimeZone(tzID);
// verify id of returned time zone (getTimeZone defaults to "GMT")
if (!tz.getID().equals(tzID))
{
Modified:
kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/Tools.java
===================================================================
---
kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/Tools.java 2011-09-06
09:24:05 UTC (rev 4867)
+++
kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/Tools.java 2011-09-06
09:43:03 UTC (rev 4868)
@@ -23,6 +23,7 @@
import java.util.Map;
import java.util.Properties;
import java.util.Set;
+import java.util.TimeZone;
/**
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
@@ -30,8 +31,12 @@
*/
public class Tools
{
-
/**
+ * All the time zones already registered
+ */
+ private static volatile Map<String, TimeZone> TIME_ZONES = new
HashMap<String, TimeZone>();
+
+ /**
* Instantiates a {@link HashSet} object and fills it with the provided element
array.
*
* @param elements the list of elements to add
@@ -155,4 +160,34 @@
String suffix = s.substring(s.length() - end.length());
return suffix.equalsIgnoreCase(end);
}
+
+ /**
+ * This method is similar to {@link TimeZone#getTimeZone(String)} with less
contention
+ */
+ public static TimeZone getTimeZone(String ID)
+ {
+ if (ID == null)
+ {
+ throw new NullPointerException("ID of the timezone cannot be null");
+ }
+ if (ID.length() == 0)
+ {
+ throw new IllegalArgumentException("ID of the timezone cannot be
empty");
+ }
+ TimeZone tz = TIME_ZONES.get(ID);
+ if (tz == null)
+ {
+ synchronized (TimeZone.class)
+ {
+ if (tz == null)
+ {
+ tz = TimeZone.getTimeZone(ID);
+ Map<String, TimeZone> tzs = new HashMap<String,
TimeZone>(TIME_ZONES);
+ tzs.put(ID, tz);
+ TIME_ZONES = tzs;
+ }
+ }
+ }
+ return tz;
+ }
}
Show replies by date