I was just curious as to whether this was a hotspot or not. I mean as Ryan
said if its not a part of high perf code path then its ok.
Also now I'm wondering why can't we do a putIfAbsent? More like
HConnectionKey connectionKey = new HConnectionKey(conf);
HConnectionImplementation connection
= HBASE_INSTANCES.get(connectionKey);
if(connection==null){
synchronized (HBASE_INSTANCES) {
if (connection == null) {
connection = new HConnectionImplementation(conf);
HBASE_INSTANCES.put(connectionKey, connection);
}
}
connection.incCount();// Making this act on an AtomicInteger
return connection;
This would work just fine right ??
Cheers,
Akash A
On Thu, Aug 25, 2011 at 3:42 AM, Stack <[email protected]> wrote:
> How would double-checked -- a problematic pattern at the best of times
> in java (see http://en.wikipedia.org/wiki/Double-checked_locking) --
> help here? What you thinking? We can't really do putIfAbsent w/ a
> connection instance?
>
> Good on you Akash,
> St.Ack
>
> On Tue, Aug 23, 2011 at 11:45 AM, Akash Ashok <[email protected]>
> wrote:
> > Hi,
> > I have pasted the code below for HConnectionManager.getConnection
> >
> > public static HConnection getConnection(Configuration conf)
> > throws ZooKeeperConnectionException {
> > HConnectionKey connectionKey = new HConnectionKey(conf);
> > synchronized (HBASE_INSTANCES) {
> > HConnectionImplementation connection =
> > HBASE_INSTANCES.get(connectionKey);
> > if (connection == null) {
> > connection = new HConnectionImplementation(conf);
> > HBASE_INSTANCES.put(connectionKey, connection);
> > }
> > connection.incCount();
> > return connection;
> > }
> > }
> >
> > just curious as to why double checked locking isn't implemented here ? Is
> it
> > because there's won't be too many threads calling this method
> simultaneouly.
> > ?
> >
> > Cheers,
> > Akash A
> >
>