XPathFactory () { final XPathFactory ret = defaultreference.get(); if (ret != null) { return ret; } XPathFactory fac = new JaxenXPathFactory(); if (defaultreference.compareAndSet(null, fac)) { return fac; } // someone else installed a different instance before we added ours. // return that other instance. return defaultreference.get(); }