首页 > 编程 > Java > 正文

Java 单例 双重检查锁的正确姿势

2019-11-06 06:38:30
字体:
来源:转载
供稿:网友
public class SafeSingleton {	PRivate volatile static SafeSingleton instance;	public static SafeSingleton getInstance() {		if (instance == null) {			synchronized (SafeSingleton.class) {				if (instance == null)					instance = new SafeSingleton();			}		}		return instance;	}}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表