The first
public class SingtenDemo1 {
private volatile static SingtenDemo1 singleton;
private SingtenDemo1 (){}
public static SingtenDemo1 getSingleton() {
if (singleton == null) {
synchronized (SingtenDemo1.class) {
if (singleton == null) {
singleton = new SingtenDemo1();
}
}
}
return singleton;
}
}
the second
public class SingtenDemo2 {
private static SingtenDemo2 instance = null;
static{
instance = new SingtenDemo2();
}
private SingtenDemo2(){}
public static SingtenDemo2 getInstance(){
return instance;
}
}
the third
public enum SingtenDemo {
INSTANCE;
}
The third singleton pattern supports serialization and deserialization by default.