欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Java單例模式、饑餓模式代碼實(shí)例

 更新時(shí)間:2015年05月19日 11:34:43   投稿:junjie  
這篇文章主要介紹了Java單例模式、饑餓模式代碼實(shí)例,本文直接給出代碼實(shí)例,需要的朋友可以參考下
class MyThreadScopeData {
 
    // 單例
    private MyThreadScopeData() {
    }
 
    // 提供獲取實(shí)例方法
    public static synchronized MyThreadScopeData getThreadInstance() {
        // 從當(dāng)前線程范圍內(nèi)數(shù)據(jù)集中獲取實(shí)例對象
        MyThreadScopeData instance = map.get();
        if (instance == null) {
            instance = new MyThreadScopeData();
            map.set(instance);
        }
        return instance;
    }
 
    // 將實(shí)例對象存入當(dāng)前線程范圍內(nèi)數(shù)據(jù)集中
    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;
    }
}

相關(guān)文章

最新評論