i have singleton class read properties xml file has quite huge number of elements.currently, reading xml file inside constructor of singleton class. once entries in xml read, can access singleton instance without having read xml again , again. know if correct approach or there better way done this.
if want lazily load properties, can write class below, work in multi-threaded environment well.
class singleton { private static singleton instance; private properties xmlproperties; private singleton() {} public static singleton getinstance() { if(instance == null) { synchronized(singleton.class) { if(instance == null) { instance = new singleton(); } } } return instance; } public properties getxmlproperties() { if(xmlproperties == null) { initproperties(); } return xmlproperties; } private synchronized void initproperties() { if(xmlproperties == null) { //initialize properties xml properties file // xmlproperties = (properties xml file) } } }