diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index f7c5dd521a5..f0651e93b24 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -750,6 +750,9 @@ Release 0.23.4 - UNRELEASED HADOOP-8843. Old trash directories are never deleted on upgrade from 1.x (jlowe) + HADOOP-8684. Deadlock between WritableComparator and WritableComparable. + (Jing Zhao via suresh) + Release 0.23.3 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/WritableComparator.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/WritableComparator.java index 9d4087f1cd6..d2cbe3bd621 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/WritableComparator.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/WritableComparator.java @@ -18,8 +18,9 @@ package org.apache.hadoop.io; -import java.io.*; -import java.util.*; +import java.io.DataInput; +import java.io.IOException; +import java.util.concurrent.ConcurrentHashMap; import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceStability; @@ -38,12 +39,11 @@ import org.apache.hadoop.util.ReflectionUtils; @InterfaceStability.Stable public class WritableComparator implements RawComparator { - private static HashMap comparators = - new HashMap(); // registry + private static final ConcurrentHashMap comparators + = new ConcurrentHashMap(); // registry /** Get a comparator for a {@link WritableComparable} implementation. */ - public static synchronized - WritableComparator get(Class c) { + public static WritableComparator get(Class c) { WritableComparator comparator = comparators.get(c); if (comparator == null) { // force the static initializers to run @@ -76,12 +76,10 @@ public class WritableComparator implements RawComparator { /** Register an optimized comparator for a {@link WritableComparable} * implementation. Comparators registered with this method must be * thread-safe. */ - public static synchronized void define(Class c, - WritableComparator comparator) { + public static void define(Class c, WritableComparator comparator) { comparators.put(c, comparator); } - private final Class keyClass; private final WritableComparable key1; private final WritableComparable key2;