Is a singleton class thread-safe in Java?

No, a Singleton class is not thread-safe by default. In a multithreaded environment, if multiple threads attempt to create the Singleton instance simultaneously, more than one object may be created. To make a Singleton thread-safe, additional synchronization mechanisms must be used.

Key Points

Example

Suppose two threads call getInstance() at the same time. If the instance has not yet been created, both threads may create separate objects, violating the Singleton principle.

public class Singleton {

    private static Singleton instance;

    private Singleton() {
    }

    public static synchronized Singleton getInstance() {

        if (instance == null) {
            instance = new Singleton();
        }

        return instance;
    }
}

Alternative Thread-Safe Approach (Eager Initialization)

public class Singleton {

    private static final Singleton INSTANCE = new Singleton();

    private Singleton() {
    }

    public static Singleton getInstance() {
        return INSTANCE;
    }
}

Benefits of Thread-Safe Singleton

Interview Tip

A concise interview answer is

A Singleton class is not thread-safe by default. In a multithreaded environment, multiple threads may create multiple instances simultaneously. To make it thread-safe, we can use synchronized methods, eager initialization, double-checked locking, or the Bill Pugh Singleton pattern.

Last updated: 11 November 2026

Previous question: How do you create a singleton class in Java?

Next question: What is a constructor in Java?

More Core Java - Level II interview questions

All Core Java - Level II questions