You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@uniffle.apache.org by "turboFei (via GitHub)" <gi...@apache.org> on 2023/03/28 09:13:18 UTC

[GitHub] [incubator-uniffle] turboFei commented on a diff in pull request #766: [#519] Speed up ConcurrentHashMap#computeIfAbsent

turboFei commented on code in PR #766:
URL: https://github.com/apache/incubator-uniffle/pull/766#discussion_r1150278831


##########
common/src/main/java/org/apache/uniffle/common/util/JavaUtils.java:
##########
@@ -36,4 +40,27 @@ public static void closeQuietly(Closeable closeable) {
       logger.error("IOException should not have been thrown.", e);
     }
   }
+
+  public static <K, V> ConcurrentHashMap<K, V> newConcurrentMap() {
+    if (SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_9)) {
+      return new ConcurrentHashMap();
+    } else {
+      return new ConcurrentHashMapForJDK8();
+    }
+  }
+
+  /**
+   * For JDK8, there is bug for ConcurrentHashMap#computeIfAbsent, checking the key existence to
+   * speed up. See details in issue #519
+   */
+  private static class ConcurrentHashMapForJDK8<K, V> extends ConcurrentHashMap<K, V> {
+    @Override
+    public V computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction) {
+      V result;
+      if (null == (result = get(key))) {

Review Comment:
   Will try it,thanks



-- 
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: issues-unsubscribe@uniffle.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@uniffle.apache.org
For additional commands, e-mail: issues-help@uniffle.apache.org