如何正确的使用单例

通常,我们的单例模式都需要有一个静态的函数来获取instance,如:

1
2
3
4
5
6
public static synchronized DataManager getInstance() {
    if (null == sInstance) {
      	sInstance = new DataManager();
    }
    return sInstance;
}

在使用的时候,我们可以: