提交 eb282e9a 编写于 作者: C chegar

6967684: httpserver using a non thread-safe SimpleDateFormat

Reviewed-by: michaelm
上级 589fccae
...@@ -52,14 +52,16 @@ class ExchangeImpl { ...@@ -52,14 +52,16 @@ class ExchangeImpl {
boolean http10 = false; boolean http10 = false;
/* for formatting the Date: header */ /* for formatting the Date: header */
static TimeZone tz; private static final String pattern = "EEE, dd MMM yyyy HH:mm:ss zzz";
static DateFormat df; private static final TimeZone gmtTZ = TimeZone.getTimeZone("GMT");
static { private static final ThreadLocal<DateFormat> dateFormat =
String pattern = "EEE, dd MMM yyyy HH:mm:ss zzz"; new ThreadLocal<DateFormat>() {
tz = TimeZone.getTimeZone ("GMT"); @Override protected DateFormat initialValue() {
df = new SimpleDateFormat (pattern, Locale.US); DateFormat df = new SimpleDateFormat(pattern, Locale.US);
df.setTimeZone (tz); df.setTimeZone(gmtTZ);
} return df;
}
};
private static final String HEAD = "HEAD"; private static final String HEAD = "HEAD";
...@@ -206,7 +208,7 @@ class ExchangeImpl { ...@@ -206,7 +208,7 @@ class ExchangeImpl {
PlaceholderOutputStream o = getPlaceholderResponseBody(); PlaceholderOutputStream o = getPlaceholderResponseBody();
tmpout.write (bytes(statusLine, 0), 0, statusLine.length()); tmpout.write (bytes(statusLine, 0), 0, statusLine.length());
boolean noContentToSend = false; // assume there is content 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 */ /* check for response type that is not allowed to send a body */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册