As the double lock checking doesn't work on optimized compilers I am removing it from my singleton class and instead of going for early initialization.
Below is my new singleton class :
class MySingleton {
private static volatile MySingleton myInstance = new MySingleton();
public static getInstance() {
return myInstance;
}
}
Apart from getInstance(), there are setter methods in the class which set the values of the member fields.
Hope this implementation will not cause any data inconsistency when multiple threads will be updating various member fields using the same object.
Any suggestions or inputs are welcome.