From 4d2bdd36d6f251600e4b27af1d2bcdd27e4f6ee0 Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Mon, 20 Jul 2015 09:41:19 +0000 Subject: [PATCH] SOLR-7803: Use Java 8 ThreadLocal git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1691900 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/solr/util/DateFormatUtil.java | 20 ++++--------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/util/DateFormatUtil.java b/solr/core/src/java/org/apache/solr/util/DateFormatUtil.java index f06118af6c3..b3268da9027 100644 --- a/solr/core/src/java/org/apache/solr/util/DateFormatUtil.java +++ b/solr/core/src/java/org/apache/solr/util/DateFormatUtil.java @@ -48,13 +48,15 @@ public final class DateFormatUtil { public static final Locale CANONICAL_LOCALE = Locale.ROOT; public static final String NOW = "NOW"; public static final char Z = 'Z'; + + private static final ISO8601CanonicalDateFormat FORMAT_PROTOTYPE = new ISO8601CanonicalDateFormat(); + /** * Thread safe DateFormat that can format in the canonical * ISO8601 date format, not including the trailing "Z" (since it is * left off in the internal indexed values) */ - public final static ThreadLocalDateFormat FORMAT_THREAD_LOCAL - = new ThreadLocalDateFormat(new ISO8601CanonicalDateFormat()); + public final static ThreadLocal FORMAT_THREAD_LOCAL = ThreadLocal.withInitial(FORMAT_PROTOTYPE::clone); private DateFormatUtil() {} @@ -241,18 +243,4 @@ public final class DateFormatUtil { return c; } } - - public static class ThreadLocalDateFormat extends ThreadLocal { - private final DateFormat proto; - - public ThreadLocalDateFormat(DateFormat d) { - super(); - proto = d; - } - - @Override - protected DateFormat initialValue() { - return (DateFormat) proto.clone(); - } - } }