Skip to content

Commit

Permalink
Fix buggy doubly locked initialization pattern; add volatile
Browse files Browse the repository at this point in the history
  • Loading branch information
rantav committed Jun 20, 2010
1 parent 9e6b286 commit 27a281d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Make the calls of other meta API go through CassandraCluster and by that use an
Add an exception hierarchy to wrap transport and general cassandra API exceptions http://github.com/rantav/hector/issues#issue/32
Make HectorException extend RuntimeException
Add the port number to be part of the cassandra host identifier so that many cassandra instances can be connected from a single hector client, http://github.com/rantav/hector/issues/issue/37/#comment_278773
Fix bogus doubly locked initialization in CassandraClientPoolFactory

0.6.0-14
========
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public enum CassandraClientPoolFactory {

INSTANCE;

private CassandraClientPool defaultPool;
private volatile CassandraClientPool defaultPool;

private static final Logger log = LoggerFactory.getLogger(CassandraClientPoolFactory.class);

Expand All @@ -35,14 +35,16 @@ public static CassandraClientPoolFactory getInstance() {
* @return
*/
public CassandraClientPool get() {
if (defaultPool == null) {
synchronized (INSTANCE) {
if (defaultPool == null) {
defaultPool = createDefault();
CassandraClientPool tmp = defaultPool;
if (tmp == null) {
synchronized(this) {
tmp = defaultPool;
if (tmp == null) {
defaultPool = tmp = createDefault();
}
}
}
return defaultPool;
return tmp;
}

/**
Expand Down

0 comments on commit 27a281d

Please sign in to comment.