From e5a9d672f0068dc953430678b52dbc18874921b4 Mon Sep 17 00:00:00 2001 From: Suresh Srinivas Date: Fri, 31 Aug 2012 17:01:25 +0000 Subject: [PATCH] HADOOP-8684. Deadlock between WritableComparator and WritableComparable. Contributed by Jing Zhao git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1379506 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-common-project/hadoop-common/CHANGES.txt | 3 +++ .../org/apache/hadoop/io/WritableComparator.java | 16 +++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 83065d89f7..6ae9e03a5d 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -197,6 +197,9 @@ Trunk (unreleased changes) HADOOP-8623. hadoop jar command should respect HADOOP_OPTS. (Steven Willis via suresh) + HADOOP-8684. Deadlock between WritableComparator and WritableComparable. + (Jing Zhao via suresh) + OPTIMIZATIONS HADOOP-7761. Improve the performance of raw comparisons. (todd) 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 9d4087f1cd..d2cbe3bd62 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 @@ @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 @@ private static void forceInit(Class cls) { /** 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;