In our project, we often use a utility class and its static methods to load some icons. This utility class is singleton.
But in the running environment, we find 314 instances of this class, under which circumstances does that occur?
In our project, we often use a utility class and its static methods to load some icons. This utility class is singleton.
But in the running environment, we find 314 instances of this class, under which circumstances does that occur?
A static utility class isn't quite the same as a singleton class. (A singleton class is where there is exactly one instance and you access its instance methods, not static methods.) If you don't want instances of your class being created, make sure there is at least one declared constructor and that all constructors are declared private. All places where you are creating instances should then light up as compiler errors.
When more than one class loader is involved.
Could you post your implementation? It sounds like you are instantiating the static class multiple times. Is your constructor private? Are you implementing the getInstance method correctly?