Summary

Code that supports SINGLETON ensures that a class has only one instance and provides a global point of access to it. A common way to achieve this is through lazy-initialization of a singleton object, instantiating it only when the singleton is first needed. In a multithreaded environment, you must take care to manage the collaboration of threads that may access a singleton's methods and data at approximately the same time. Regardless of the mechanics that you apply, the value of SINGLETON lies in centralizing authority in a single object.

Get Design Patterns Java™ Workbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.