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;
}
}