0

Is this singleton implementation OK in a multi threaded application given: there is no serialization, deserialization

public class NewSingleton {

    private static final NewSingleton RAJNI= new NewSingleton();

    private NewSingleton(){

    }

    public static NewSingleton getInstance() {
        return RAJNI;
    }    
}
Pshemo
  • 122,468
  • 25
  • 185
  • 269
abipc87
  • 11

1 Answers1

6

This is fine if you make the class final but I prefer

public enum NewSingleton {
    INSTANCE;
}

as it is much simpler IMHO.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130