package com.mgy;
//懒汉式(存在线程安全问题)
public class TestSingleton1 {
public static void main(String[] args){
Singleton1 s1=Singleton1.getSingleton1();
Singleton1 s2=Singleton1.getSingleton1();
System.out.println(s1);
System.out.println(s2.toString());
}
}
class Singleton1{
private Singleton1(){
}
private static Singleton1 s;
public static Singleton1 getSingleton1(){
if(s==null){
s=new Singleton1();
}
return s;
}
}
//懒汉式(存在线程安全问题)
public class TestSingleton1 {
public static void main(String[] args){
Singleton1 s1=Singleton1.getSingleton1();
Singleton1 s2=Singleton1.getSingleton1();
System.out.println(s1);
System.out.println(s2.toString());
}
}
class Singleton1{
private Singleton1(){
}
private static Singleton1 s;
public static Singleton1 getSingleton1(){
if(s==null){
s=new Singleton1();
}
return s;
}
}