You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2022/09/07 03:02:37 UTC

[GitHub] [rocketmq] mxsm commented on a diff in pull request #5008: [ISSUE #4999]Optimize ConcurrentMap#computeIfAbsent performance on jdk1.8 a workaround

mxsm commented on code in PR #5008:
URL: https://github.com/apache/rocketmq/pull/5008#discussion_r964337674


##########
common/src/main/java/org/apache/rocketmq/common/utils/ConcurrentHashMapUtils.java:
##########
@@ -39,10 +37,11 @@ private ConcurrentHashMapUtil() {
      */
     public static <K, V> V computeIfAbsent(ConcurrentMap<K, V> map, K key, Function<? super K, ? extends V> func) {
         if (IS_JDK8) {
-            V v, newValue;
-            return ((v = map.get(key)) == null &&
-                (newValue = func.apply(key)) != null &&
-                (v = map.putIfAbsent(key, newValue)) == null) ? newValue : v;
+            V v = map.get(key);
+            if (null == v) {
+                v = map.computeIfAbsent(key, func);
+            }
+            return v;

Review Comment:
   > Could you also provide JMH test results for this change?
   Ok I will 
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org