diff options
author | Bjørn Christian Seime <bjorncs@oath.com> | 2018-02-02 13:55:21 +0100 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@oath.com> | 2018-02-02 14:01:42 +0100 |
commit | f3708b34b19140aa1e59601b974879f433048152 (patch) | |
tree | 030c7f3d1a8603a16bd7bbd065cf0ee8af5b5535 /container-accesslogging | |
parent | 468e0e16a60a5feaf6d5eec971ff06078b6bb694 (diff) |
SimpleDateFormat is not thread-safe
Diffstat (limited to 'container-accesslogging')
-rw-r--r-- | container-accesslogging/src/main/java/com/yahoo/container/logging/VespaAccessLog.java | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/container-accesslogging/src/main/java/com/yahoo/container/logging/VespaAccessLog.java b/container-accesslogging/src/main/java/com/yahoo/container/logging/VespaAccessLog.java index 3a0713142df..054fc0fcbf7 100644 --- a/container-accesslogging/src/main/java/com/yahoo/container/logging/VespaAccessLog.java +++ b/container-accesslogging/src/main/java/com/yahoo/container/logging/VespaAccessLog.java @@ -14,7 +14,7 @@ import java.util.logging.Level; */ public final class VespaAccessLog implements AccessLogInterface { - private static final SimpleDateFormat dateFormat = createDateFormat(); + private static final ThreadLocal<SimpleDateFormat> dateFormat = ThreadLocal.withInitial(VespaAccessLog::createDateFormat); private final AccessLogHandler logHandler; @@ -28,9 +28,8 @@ public final class VespaAccessLog implements AccessLogInterface { return format; } - private String getDate () { - Date date = new Date(); - return dateFormat.format(date); + private static String getDate() { + return dateFormat.get().format(new Date()); } private String getRequest(final String httpMethod, final String rawPath, final String rawQuery, final String httpVersion) { @@ -41,7 +40,7 @@ public final class VespaAccessLog implements AccessLogInterface { return (user == null) ? "-" : user; } - private void writeLog(String ipAddr, String user, String request, String referer, String agent, long startTime, + private void writeLog(String ipAddr, String user, String request, String referer, String agent, long durationMillis, long byteCount, HitCounts hitcounts, int returnCode) { long ms = Math.max(0L, durationMillis); @@ -104,7 +103,6 @@ public final class VespaAccessLog implements AccessLogInterface { accessLogEntry.getHttpVersion()), accessLogEntry.getReferer(), accessLogEntry.getUserAgent(), - accessLogEntry.getTimeStampMillis(), accessLogEntry.getDurationBetweenRequestResponseMillis(), accessLogEntry.getReturnedContentSize(), accessLogEntry.getHitCounts(), |