You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2022/03/20 18:27:57 UTC

[commons-lang] 02/06: Better concurrency with the Java 8 API ConcurrentMap#computeIfAbsent().

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git

commit 5648bc42e2f618bd230e815eb36964d2fd62d303
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Mar 20 14:06:39 2022 -0400

    Better concurrency with the Java 8 API ConcurrentMap#computeIfAbsent().
---
 .../java/org/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 049040b..fea3347 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<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);
+        });
     }
 
     /**