diff --git src/main/java/org/apache/hadoop/hbase/ipc/HBaseClient.java src/main/java/org/apache/hadoop/hbase/ipc/HBaseClient.java index 235c078..66d0e7b 100644 --- src/main/java/org/apache/hadoop/hbase/ipc/HBaseClient.java +++ src/main/java/org/apache/hadoop/hbase/ipc/HBaseClient.java @@ -73,7 +73,7 @@ public class HBaseClient { private static final Log LOG = LogFactory .getLog("org.apache.hadoop.ipc.HBaseClient"); - protected final PoolMap connections; + protected volatile PoolMap connections; protected final Class valueClass; // class of call values protected int counter; // counter for call ids @@ -1131,11 +1131,15 @@ public class HBaseClient { * refs for keys in HashMap properly. For now its ok. */ ConnectionId remoteId = new ConnectionId(addr, protocol, ticket, rpcTimeout); - synchronized (connections) { - connection = connections.get(remoteId); - if (connection == null) { - connection = createConnection(remoteId); - connections.put(remoteId, connection); + connection = connections.get(remoteId); + if (connection == null) { + synchronized (connections) { + // Recheck since some other thread could have added a connection. + connection = connections.get(remoteId); + if (connection == null) { + connection = createConnection(remoteId); + connections.put(remoteId, connection); + } } } connection.addCall(call);