I'm attempting to make a thread-safe singleton. The program will run if I remove the synchronized function and uncomment the condition but then it won't be thread-safe, correct?
I'm java a newbie (and new to working with threads).
class Singleton {
    volatile public static Singleton instance = null;
    private String someText;
    private Singleton() {
        this.someText = "Only one instance of this class can be created!";
    }
    public static Singleton getInstance() {
        synchronized (instance) {
            if(instance == null) {
                instance = new Singleton();
            }
        }
        // this will run
        // if (instance == null) {
        //  instance = new Singleton():
        // }
        return instance;
    }
    public String getSomeText() {
        return this.someText;
    }
    public void setSomeText(String text) {
        this.someText = text;
    }
}
public class Assignment1 {
    /*
        Assignment 1
        Implement a Singleton with double-checked locking.
    */
    public static void main(String[] args) {
        Singleton singleton1 = Singleton.getInstance();
        Singleton singleton2 = Singleton.getInstance();
        System.out.println(singleton1.getSomeText());
        System.out.println(singleton2.getSomeText());
        singleton1.setSomeText("Here's our new text!");
        System.out.println(singleton1.getSomeText());
        System.out.println(singleton2.getSomeText());
    }
}
 
    