package com.mycontainer;
public class MyContainer {
private static ContainerConfig cConfig;
private MyContainer() {
}
public static ContainerConfig getConfiguration() {
if (cConfig == null)
cConfig = new ContainerConfig();
return cConfig;
}
}
package com.mycontainer; public class MyContainer { private static ContainerConfig cConfig; private MyContainer() { }
Share
I would have to say that it is a poor implementation of the lazy initialization and Singleton pattern. There is no synchronization and hence no thread safety. Under multiple threads accessing this code you may end up with more than one instance.
Update: It is better to have your code like this: