Tuesday, May 22, 2007

All about singletons

This is a little bit old but quite thorough article about singletons. It addresses all singleton issues with concurrency, classloading and serialization. However, the fourth implemention of a thread-safe singleton (Example 7) misses the lazy-loading requirement (the singleton instance is not created when first accessed but earlier at class loading). This article gives a different implementation that is both thread-safe and lazy-loaded and this explains why. See also the discussion here.

No comments: