28 lines
713 B
Java
Executable File
28 lines
713 B
Java
Executable File
package com.zeekling.simgleton;
|
|
|
|
/**
|
|
* Created by lzh on 3/30/16.
|
|
*/
|
|
public class LazySingleton {
|
|
private static LazySingleton lazySimgleton = null;
|
|
private LazySingleton(){}
|
|
public static LazySingleton getInstance(){
|
|
//线程不安全
|
|
// if(lazySimgleton == null){
|
|
// lazySimgleton = new LazySingleton();
|
|
// }
|
|
//线程安全
|
|
if(lazySimgleton == null){
|
|
synchronized(LazySingleton.class){
|
|
if(lazySimgleton == null){
|
|
lazySimgleton = new LazySingleton();
|
|
}
|
|
}
|
|
}
|
|
return lazySimgleton;
|
|
}
|
|
public void say(){
|
|
System.out.println("I am lazy");
|
|
}
|
|
}
|