# HG changeset patch # User chegar # Date 1278954995 -3600 # Node ID 6aed6c9c974da7c1b450795e1613946ee91b1da2 # Parent 4df5b9bcf842c5d3a0ae37a57e0f0a87dcef851f 6967684: httpserver using a non thread-safe SimpleDateFormat Reviewed-by: michaelm diff -r 4df5b9bcf842 -r 6aed6c9c974d jdk/src/share/classes/sun/net/httpserver/ExchangeImpl.java --- a/jdk/src/share/classes/sun/net/httpserver/ExchangeImpl.java Mon Jul 12 18:13:40 2010 +0100 +++ b/jdk/src/share/classes/sun/net/httpserver/ExchangeImpl.java Mon Jul 12 18:16:35 2010 +0100 @@ -52,14 +52,16 @@ boolean http10 = false; /* for formatting the Date: header */ - static TimeZone tz; - static DateFormat df; - static { - String pattern = "EEE, dd MMM yyyy HH:mm:ss zzz"; - tz = TimeZone.getTimeZone ("GMT"); - df = new SimpleDateFormat (pattern, Locale.US); - df.setTimeZone (tz); - } + private static final String pattern = "EEE, dd MMM yyyy HH:mm:ss zzz"; + private static final TimeZone gmtTZ = TimeZone.getTimeZone("GMT"); + private static final ThreadLocal dateFormat = + new ThreadLocal() { + @Override protected DateFormat initialValue() { + DateFormat df = new SimpleDateFormat(pattern, Locale.US); + df.setTimeZone(gmtTZ); + return df; + } + }; private static final String HEAD = "HEAD"; @@ -206,7 +208,7 @@ PlaceholderOutputStream o = getPlaceholderResponseBody(); tmpout.write (bytes(statusLine, 0), 0, statusLine.length()); boolean noContentToSend = false; // assume there is content - rspHdrs.set ("Date", df.format (new Date())); + rspHdrs.set ("Date", dateFormat.get().format (new Date())); /* check for response type that is not allowed to send a body */