samedi 8 décembre 2018

Is static final (eager) singleton thread safe in java?

If I create a singleton object using static final then will it be thread safe? here is the example code?

public class StaticSingleton {
    private static final StaticSingleton instance = new StaticSingleton();

    private StaticSingleton() {
    }

    public static StaticSingleton GetInstance() {
        return instance;
    }
}

Aucun commentaire:

Enregistrer un commentaire