From 5648bc42e2f618bd230e815eb36964d2fd62d303 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sun, 20 Mar 2022 14:06:39 -0400 Subject: [PATCH] Better concurrency with the Java 8 API ConcurrentMap#computeIfAbsent(). --- .../apache/commons/lang3/time/FastDateParser.java | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/time/FastDateParser.java b/src/main/java/org/apache/commons/lang3/time/FastDateParser.java index 049040b8f..fea334711 100644 --- a/src/main/java/org/apache/commons/lang3/time/FastDateParser.java +++ b/src/main/java/org/apache/commons/lang3/time/FastDateParser.java @@ -653,16 +653,9 @@ public class FastDateParser implements DateParser, Serializable { */ private Strategy getLocaleSpecificStrategy(final int field, final Calendar definingCalendar) { final ConcurrentMap 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); + }); } /**