Author: markt Date: Fri Mar 6 14:13:05 2009 New Revision: 750911 URL: http://svn.apache.org/viewvc?rev=750911&view=rev Log: Use ThreadLocal rather than syncs for DateFormat to prevent potential bottleneck in cookie creation
Modified: tomcat/tc6.0.x/trunk/ (props changed) tomcat/tc6.0.x/trunk/STATUS.txt tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/http/ServerCookie.java tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml Propchange: tomcat/tc6.0.x/trunk/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Fri Mar 6 14:13:05 2009 @@ -1 +1 @@ -/tomcat/trunk:601180,606992,612607,630314,640888,652744,653247,673796,673820,683982,684001,684081,684234,684269-684270,685177,687503,687645,689402,690781,691392,691805,692748,693378,694992,695053,695311,696780,696782,698012,698227,698236,698613,699427,699634,701355,709294,709811,709816,710063,710066,710125,710205,711126,711600,712461,712467,718360,719602,719626,719628,720046,720069,721040,723404,723738,726052,727303,728032,728768,728947,729057,729567,729569,729571,729809,729815,729934,730250,730590,731651,732859,732863,734734,740675,740684,742677,742697,742714,744160,747834,748344 +/tomcat/trunk:601180,606992,612607,630314,640888,652744,653247,673796,673820,683982,684001,684081,684234,684269-684270,685177,687503,687645,689402,690781,691392,691805,692748,693378,694992,695053,695311,696780,696782,698012,698227,698236,698613,699427,699634,701355,709294,709811,709816,710063,710066,710125,710205,711126,711600,712461,712467,718360,719602,719626,719628,720046,720069,721040,723404,723738,726052,727303,728032,728768,728947,729057,729567,729569,729571,729809,729815,729934,730250,730590,731651,732859,732863,734734,740675,740684,742677,742697,742714,744160,744238,747834,748344 Modified: tomcat/tc6.0.x/trunk/STATUS.txt URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/STATUS.txt?rev=750911&r1=750910&r2=750911&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/STATUS.txt (original) +++ tomcat/tc6.0.x/trunk/STATUS.txt Fri Mar 6 14:13:05 2009 @@ -95,12 +95,6 @@ code a warning that it won't be there in the next version. -1: -* Use ThreadLocal rather than syncs for DateFormat to prevent potential - bottleneck in cookie creation - http://svn.apache.org/viewvc?rev=744238&view=rev - +1: markt, fhanik, jim - -1: - * Fix spelling errors reported on users and dev list http://svn.apache.org/viewvc?rev=746321&view=rev http://svn.apache.org/viewvc?rev=746384&view=rev Modified: tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/http/ServerCookie.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/http/ServerCookie.java?rev=750911&r1=750910&r2=750911&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/http/ServerCookie.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/http/ServerCookie.java Fri Mar 6 14:13:05 2009 @@ -57,14 +57,20 @@ // 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<DateFormat> OLD_COOKIE_FORMAT = + new ThreadLocal<DateFormat>() { + 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)); } /** @@ -320,12 +326,10 @@ 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)); } } Modified: tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml?rev=750911&r1=750910&r2=750911&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml (original) +++ tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml Fri Mar 6 14:13:05 2009 @@ -291,6 +291,9 @@ <fix> Fix possible NCDFE when using FORM authentication. (jfclere) </fix> + <fix> + Fix possible synchronisation bottleneck in cookie creation. (markt) + </fix> </changelog> </subsection> <subsection name="Coyote"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org