当前位置:网站首页>Singleton DCL (double check the lock) full han mode and the hungry

Singleton DCL (double check the lock) full han mode and the hungry

2022-08-09 06:33:00 The strongest disciple in history

public class Test29 {public static void main(String[] args) {SingleObject singleObject = SingleObject.getSingleObject();}}//Singleton hungry modeclass SingleObject2{private static volatile SingleObject2 singleObject = new SingleObject2();private SingleObject2 (){}public static SingleObject2 getSingleObject(){return singleObject;}}//Singleton full Chinese modeclass SingleObject{private static volatile SingleObject singleObject;private SingleObject (){}//double Check lockpublic static SingleObject getSingleObject(){if(singleObject == null){synchronized (SingleObject.class){if(singleObject == null){singleObject = new SingleObject();}}}return singleObject;}}

原网站

版权声明
本文为[The strongest disciple in history]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/221/202208090629204432.html