virajjasani commented on PR #4874:
URL: https://github.com/apache/hbase/pull/4874#issuecomment-1332760175
This is worth giving a shot, this would avoid us having coarse-grained lock
on the entire Map:
```
private static final ConcurrentMap<String, MetricsConnection>
METRICS_INSTANCES =
new ConcurrentHashMap<>();
static MetricsConnection getMetricsConnection(final String scope,
Supplier<ThreadPoolExecutor> batchPool, Supplier<ThreadPoolExecutor>
metaPool) {
return METRICS_INSTANCES.compute(scope, (s, metricsConnection) -> {
if(metricsConnection == null) {
MetricsConnection newMetricsConn = new MetricsConnection(scope,
batchPool, metaPool);
newMetricsConn.incrConnectionCount();
return newMetricsConn;
} else {
metricsConnection.addThreadPools(batchPool, metaPool);
metricsConnection.incrConnectionCount();
return metricsConnection;
}
});
}
static void deleteMetricsConnection(final String scope) {
METRICS_INSTANCES.computeIfPresent(scope, (s, metricsConnection) -> {
metricsConnection.decrConnectionCount();
if (metricsConnection.getConnectionCount() == 0) {
return null;
}
return metricsConnection;
});
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]