The Singleton pattern restricts a class to exactly one instance and provides a single, well-known access point to it, which is useful whenever a single shared object must coordinate state or behavior across an entire application.
A ConnectionPool that manages a fixed set of database connections should exist as a single shared instance, since creating multiple independent pools would waste resources and could exceed the database's connection limit.
public class SingletonDemo {
// Thread-safe, lazy Singleton using the holder idiom
static final class ConnectionPool {
private ConnectionPool() {
System.out.println("Creating the pool (runs once)");
}
private static class Holder {
static final ConnectionPool INSTANCE = new ConnectionPool();
}
static ConnectionPool getInstance() {
return Holder.INSTANCE;
}
}
public static void main(String[] args) {
ConnectionPool a = ConnectionPool.getInstance();
ConnectionPool b = ConnectionPool.getInstance();
System.out.println("Same instance: " + (a == b));
}
}Creating the pool (runs once)
Same instance: true
A concise interview answer is
Singleton guarantees a class has exactly one instance with a single global access point, which is useful for coordinating shared resources like a configuration manager or connection pool — but I'm careful not to overuse it, since it introduces global state that can make code harder to test.
Last updated: 1 November 2026
Next question: How would you implement a thread-safe Singleton in Java?