Listing 5-11 shows another implementation of the Logger class that is based on the “initialization on demand holder” idiom. This idiom uses inner classes and does not use any synchronization construct (recall the discussion of inner classes in Chapter 4). It exploits the fact that inner classes are not loaded until they are referenced.
And that is what is said after the code:
Hmm…at last you’ve found an efficient working solution. However, before we close this discussion of the singleton design pattern, two parting words of caution. First, use the singleton pattern wherever it is appropriate, but do not overuse it. Second, make sure that your singleton implementation ensures the creation of only one instance even if your code is multi-threaded.
The initialise on demand is a pointless exercise in every singleton I have ever seen.
Unless the class has another externally accessible static thing other than getInstance that is going to be called independently and prior to the call to getInstance then it achieves nothing.
So either do it without the holder, or do it the way Paul suggests using an enum.
Or don't do it at all as a singleton is not something people should generally be writing anymore. They're a swine to test if they have any dependencies.