SOLR-7803: Use Java 8 ThreadLocal

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1691900 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Uwe Schindler 2015-07-20 09:41:19 +00:00
parent 50f168ed4c
commit 4d2bdd36d6
1 changed files with 4 additions and 16 deletions

View File

@ -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 <b>format</b> 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<DateFormat> 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<DateFormat> {
private final DateFormat proto;
public ThreadLocalDateFormat(DateFormat d) {
super();
proto = d;
}
@Override
protected DateFormat initialValue() {
return (DateFormat) proto.clone();
}
}
}