diff --git hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/HBaseClient.java hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/HBaseClient.java index 717259d..f368886 100644 --- hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/HBaseClient.java +++ hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/HBaseClient.java @@ -106,7 +106,7 @@ public class HBaseClient { public static final Log LOG = LogFactory.getLog("org.apache.hadoop.ipc.HBaseClient"); - protected final PoolMap connections; + protected volatile PoolMap connections; private static final Map methodInstances = new ConcurrentHashMap(); @@ -1395,11 +1395,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 another thread might have added a connection. + connection = connections.get(remoteId); + if (connection == null) { + connection = createConnection(remoteId); + connections.put(remoteId, connection); + } } } connection.addCall(call); @@ -1465,4 +1469,4 @@ public class HBaseClient { (ticket == null ? 0 : ticket.hashCode()) )) ^ rpcTimeout; } } -} \ No newline at end of file +}