首页 > 其他 > 详细

单例模式

时间:2015-05-09 23:31:57      阅读:325      评论:0      收藏:0      [点我收藏+]

 

class MyThreadScopeData {

	// 单例
	private MyThreadScopeData() {
	}

	// 提供获取实例方法
	public static synchronized MyThreadScopeData getThreadInstance() {
		// 从当前线程范围内数据集中获取实例对象
		MyThreadScopeData instance = map.get();
		if (instance == null) {
			instance = new MyThreadScopeData();
			map.set(instance);
		}
		return instance;
	}

	// 将实例对象存入当前线程范围内数据集中
	private static MyThreadScopeData instance = null; // 饥饿模式

	private String name;
	private int age;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}
}

  

单例模式

原文:http://www.cnblogs.com/linjiqin/p/4491383.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!