private Single(){}
private Single s=new Single();
private static Single getInstance(){
retutn s;
}
private Single (){}
private Single s=new Single();
private static synchronized Single getInstance(){
return s;
}
第二种就是加了一个同步,两种单例有什么区别?第一种单例模式是安全的,再加一个同步会不会造成资源浪费呢? |
|