Better concurrency with the Java 8 API ConcurrentMap#computeIfAbsent().
This commit is contained in:
parent
89bcc5f80e
commit
5648bc42e2
|
@ -653,16 +653,9 @@ public class FastDateParser implements DateParser, Serializable {
|
|||
*/
|
||||
private Strategy getLocaleSpecificStrategy(final int field, final Calendar definingCalendar) {
|
||||
final ConcurrentMap<Locale, Strategy> cache = getCache(field);
|
||||
Strategy strategy = cache.get(locale);
|
||||
if (strategy == null) {
|
||||
strategy = field == Calendar.ZONE_OFFSET ? new TimeZoneStrategy(locale)
|
||||
: new CaseInsensitiveTextStrategy(field, definingCalendar, locale);
|
||||
final Strategy inCache = cache.putIfAbsent(locale, strategy);
|
||||
if (inCache != null) {
|
||||
return inCache;
|
||||
}
|
||||
}
|
||||
return strategy;
|
||||
return cache.computeIfAbsent(locale, k -> {
|
||||
return field == Calendar.ZONE_OFFSET ? new TimeZoneStrategy(locale) : new CaseInsensitiveTextStrategy(field, definingCalendar, locale);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue