实现线程安全的 单例模式

package com.testThread;

/**
* @author shkstart
* @create 2021-08-06 10:07
*/
public class 实现线程安全的单例模式 {
public static void main(String[] args) {
Window4 w1 = Window4.getInstance();
Window4 w2 = Window4.getInstance();
System.out.println(w1==w2);
}
}

class Window4{
private static Window4 win = null;
public static Window4 getInstance(){
if(win == null){
synchronized (Window4.class){
if (win == null){
win = new Window4();
}
}
}
return win;
}
}
posted @ 2021-08-06 10:17  林**  阅读(55)  评论(0编辑  收藏  举报