单例

private  GlobalData (){
}
public static GlobalData getDefault() {
        if (instance == null) {
            synchronized (GlobalData.class) {
                if (instance == null) {
                    instance = new GlobalData();
                }
            }
        }
        return instance;
    }

推荐阅读更多精彩内容