For example, I have a class
public class EagerInitializedSingleton {
private static final EagerInitializedSingleton instance = new EagerInitializedSingleton();
public static EagerInitializedSingleton getInstance(){
return instance;
}
}
And my application have 2 activity A.java and B.java (from A I can go to B).
In B activity I have
import EagerInitializedSingleton.java;
public class B{
onCreate(...){
EagerInitializedSingleton.getInstance()...
}
}
My question is when instantiated
be instantiated`
- When launch application (before A Activity start)
- When import
EagerInitializedSingleton.java
- Or when EagerInitializedSingleton.getInstance()
If possible, can I check when be instantiated by write Log or something? Any help would be great appreciated.
UPDATE
I'm follow here to create EagerInitializedSingleton
http://www.journaldev.com/1377/java-singleton-design-pattern-best-practices-examples
And they have say
If your singleton class is not using a lot of resources, this is the approach to use. But in most of the scenarios, Singleton classes are created for resources such as File System, Database connections etc and we should avoid the instantiation until unless client calls the getInstance method
Like some answer say that instance
be instantiated when I call EagerInitializedSingleton.getInstance()...
, so who is correct?