单例模式的定义:保证一个类仅有一个实例,并提供一个访问它的全局访问点!
1、懒汉public class Singleton { private static Singleton instance; private Singleton (){} public static synchronized Singleton getInstance() { if (instance == null) { instance = new Singleton(); } return instance; } }