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
  • 118,400
  • 24
  • 176
  • 257
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
  • 513,304
  • 74
  • 731
  • 1,106