public class Singleton
{
private static Singleton uniqueInstance;
private Singleton(){
}
public static Singleton getInstance(){
if(uniqueInstance==null){
uniqueInstance=new Singleton();
}
return uniqueInstance;
}
}
以上是经典的单例模式实现代码,但是上述代码不能保证在多线程程序中正确运行,更多的知识还得慢慢学习。