Hello,
Ive read up on the use of the Singleton Pattern, which goal is to make sure that there is only one instance of the given class.
I got a multithreaded application and Ive found alot of, "bla bla bla", about the problem that can occur when
not creating the getInstance method correctly like this:
public static synchronized Singleton getInstance() {
if (instance == null) {
instance = new Singleton();
}
return instance;
}
But I cant find anything about what problems there is that can occur if you do this wrong and dont use synchronized and there is indeed two instances created instead of one.
Im using this already for my DB layer, but, what can possibly happen if there is two instances instead of one?
Also, as the instance is static, it will never get garbage collected, right? So this can only happen one time at the startup?