/** * 单例模式。 * @author Bright Lee */ public class Singleton { private static final Singleton instance = new Singleton(); private Singleton() { System.out.println("构造方法被调用了,当前时间戳是:" + System.currentTimeMillis()); } public static Singleton getInstance() { return instance; } public static void main(String[] args) { // 并发调用100遍,构造方法只会被调用一次: for (int i = 0; i < 100; i++) { new Thread() { public void run() { Singleton.getInstance(); } }.start(); } } }青蛙客服系统:https://download.csdn.net/download/look4liming/93326820