0% found this document useful (0 votes)
5 views10 pages

Java Singleton Design

The Singleton Design Pattern is a creational pattern that restricts a class to a single instance and provides global access to it, commonly used for database connections, logging systems, and configuration managers. Key characteristics include single instance creation, global access, lazy initialization, and thread safety. Various implementation methods in Java include basic non-thread-safe, thread-safe with eager initialization, synchronized methods, double-checked locking, and using a static inner class.

Uploaded by

toabhay1202
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views10 pages

Java Singleton Design

The Singleton Design Pattern is a creational pattern that restricts a class to a single instance and provides global access to it, commonly used for database connections, logging systems, and configuration managers. Key characteristics include single instance creation, global access, lazy initialization, and thread safety. Various implementation methods in Java include basic non-thread-safe, thread-safe with eager initialization, synchronized methods, double-checked locking, and using a static inner class.

Uploaded by

toabhay1202
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Singleton

Design Pattern
in Java
The Singleton Design Pattern is a creational design pattern that ensures
a class has only one instance and provides a global point of access to
that instance.
It is commonly used in scenarios where exactly one object is needed to
coordinate actions across a system, such as:
Database connections
Logging systems
Configuration managers
Caching mechanisms
Key Characteristics of Singleton
1. Single Instance: Only one instance of the class is created.
2. Global Access: The instance is globally accessible.
3. Lazy Initialization: The instance is created only when it is
needed.
4. Thread Safety: Ensures that the singleton instance is thread-safe
in multi-threaded environments.
Implementation of Singleton in Java
Basic Singleton (Non-Thread-Safe)
This is the simplest form of a singleton but is not thread-safe.
Basic Singleton (Thread-Safe with Eager Initialization)
The instance is created at the time of class loading.
Thread-Safe Singleton(Using Synchronized)
Ensures the singleton instance is thread-safe but may reduce performance due to
synchronization
Double-Checked Locking Singleton
This approach improves performance by reducing the overhead of
synchronization.
Bill Pugh Singleton (Using Static Inner Class)
This is a thread-safe and efficient way to implement a singleton
using a static inner class.
example
example

You might also like