From: markt Date: Fri, 13 Feb 2009 20:46:22 +0000 (+0000) Subject: Change to ThreadLocal to prevent potential sync bottleneck on cookie creation X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=523e18c9c48ef87870144e70ea35e547d0e00384;p=tomcat7.0 Change to ThreadLocal to prevent potential sync bottleneck on cookie creation git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@744238 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/tomcat/util/http/ServerCookie.java b/java/org/apache/tomcat/util/http/ServerCookie.java index b1662200f..8b1d2587b 100644 --- a/java/org/apache/tomcat/util/http/ServerCookie.java +++ b/java/org/apache/tomcat/util/http/ServerCookie.java @@ -57,14 +57,20 @@ public class ServerCookie implements Serializable { // Other fields private static final String OLD_COOKIE_PATTERN = "EEE, dd-MMM-yyyy HH:mm:ss z"; - private static final DateFormat OLD_COOKIE_FORMAT; + private static final ThreadLocal OLD_COOKIE_FORMAT = + new ThreadLocal() { + protected DateFormat initialValue() { + DateFormat df = + new SimpleDateFormat(OLD_COOKIE_PATTERN, Locale.US); + df.setTimeZone(TimeZone.getTimeZone("GMT")); + return df; + } + }; private static final String ancientDate; static { - OLD_COOKIE_FORMAT = new SimpleDateFormat(OLD_COOKIE_PATTERN, Locale.US); - OLD_COOKIE_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT")); - ancientDate = OLD_COOKIE_FORMAT.format(new Date(10000)); + ancientDate = OLD_COOKIE_FORMAT.get().format(new Date(10000)); } /** @@ -300,12 +306,10 @@ public class ServerCookie implements Serializable { if (maxAge == 0) buf.append( ancientDate ); else - synchronized (OLD_COOKIE_FORMAT) { - OLD_COOKIE_FORMAT.format( - new Date(System.currentTimeMillis() + - maxAge*1000L), - buf, new FieldPosition(0)); - } + OLD_COOKIE_FORMAT.get().format( + new Date(System.currentTimeMillis() + + maxAge*1000L), + buf, new FieldPosition(0)); } }