单例模式的意思就是只有一个实例。单例模式确保某一个类只有一个实例,而且自行实例化并向整个系统提供这个实例。这个类称为单例类。 public class MyBean { private static MyBean instance = null; public static synchronized MyBean getInstance(){ if(instance == null){ instance = new MyBean(); } return instance; } }