尧图建网站 尧图建网站 YAOTU WEB BUILD 免费咨询
ARTICLE DETAIL

资讯详情

深耕网站建设与建站编程的一线实战洞察。

设计模式:单例模式(Singleton Pattern、饿汉)

设计模式:单例模式(Singleton Pattern、饿汉) /** * 单例模式。 * 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
返回列表