I have read his basic Java implementation of Singleton, because I will have a presentation in my class about design patterns:
public final class ClassSingleton {
private static ClassSingleton INSTANCE;
private String info = "Initial info class";
private ClassSingleton() {
}
public static ClassSingleton getInstance() {
if(INSTANCE == null) {
INSTANCE = new ClassSingleton();
}
return INSTANCE;
}
// getters and setters
}
Having used it certain times, I'm quite familiar with it. However, when I got deeper into the topic, I found out that this version is not thread safe at all.
What does this mean exactly? If multiple threads access it and create a new instance, will more different instances be created? Or where does the "safety" cease to exist?
Thanks for your answer in advance.