Suresh Kumar Rajendran wrote:Thanks for your reply. Memory is not an issue.
In which case I agree with Anayonkar: this is
your requirement; and I'd suggest that it's spurious.
The
only reason for using lazy instantiation is because the object in question takes either
1. A lot of space.
2. A lot of time to create - in fact, I'd go further and say that it has to take so much time that it will be visible to users.
Otherwise, the standard explicit instantiation
private static final mySingleton INSTANCE = new mySingleton();
is almost always the best way to go. I've used lazy instantiation precisely once in 11 years of writing Java.
Another point to consider is whether or not this class really needs to be a singleton. At least one of the Gang of Four has said that if they were writing their '
Patterns' book again, they would probably have left it out. You may also be interested in
this article.
Winston