HBASE-10143 replace WritableFactories's hashmap with ConcurrentHashMap (Liang Xie via Stack)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1559924 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2014-01-21 05:16:19 +00:00
parent a560488df6
commit d726c27ae8
2 changed files with 9 additions and 5 deletions

View File

@ -136,6 +136,9 @@ Release 2.4.0 - UNRELEASED
HADOOP-10228. FsPermission#fromShort() should cache FsAction.values(). HADOOP-10228. FsPermission#fromShort() should cache FsAction.values().
(Haohui Mai via cnauroth) (Haohui Mai via cnauroth)
HADOOP-10143 replace WritableFactories's hashmap with ConcurrentHashMap
(Liang Xie via stack)
BUG FIXES BUG FIXES
HADOOP-9964. Fix deadlocks in TestHttpServer by synchronize HADOOP-9964. Fix deadlocks in TestHttpServer by synchronize

View File

@ -22,25 +22,26 @@ import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.classification.InterfaceStability;
import org.apache.hadoop.conf.*; import org.apache.hadoop.conf.*;
import org.apache.hadoop.util.ReflectionUtils; import org.apache.hadoop.util.ReflectionUtils;
import java.util.HashMap; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/** Factories for non-public writables. Defining a factory permits {@link /** Factories for non-public writables. Defining a factory permits {@link
* ObjectWritable} to be able to construct instances of non-public classes. */ * ObjectWritable} to be able to construct instances of non-public classes. */
@InterfaceAudience.Public @InterfaceAudience.Public
@InterfaceStability.Stable @InterfaceStability.Stable
public class WritableFactories { public class WritableFactories {
private static final HashMap<Class, WritableFactory> CLASS_TO_FACTORY = private static final Map<Class, WritableFactory> CLASS_TO_FACTORY =
new HashMap<Class, WritableFactory>(); new ConcurrentHashMap<Class, WritableFactory>();
private WritableFactories() {} // singleton private WritableFactories() {} // singleton
/** Define a factory for a class. */ /** Define a factory for a class. */
public static synchronized void setFactory(Class c, WritableFactory factory) { public static void setFactory(Class c, WritableFactory factory) {
CLASS_TO_FACTORY.put(c, factory); CLASS_TO_FACTORY.put(c, factory);
} }
/** Define a factory for a class. */ /** Define a factory for a class. */
public static synchronized WritableFactory getFactory(Class c) { public static WritableFactory getFactory(Class c) {
return CLASS_TO_FACTORY.get(c); return CLASS_TO_FACTORY.get(c);
} }