close
範例:
public class AutoStudent { // Singleton private static AutoStudent instance = null ; public static AutoStudent getInstance() { if ( instance == null ) { synchronized ( AutoStudent.class ) { if ( instance == null ) { instance = new AutoStudent(); } } // synchronized } return instance; } // getInstance() private AutoStudent() { } } // public class AutoStudent
參考:[良葛格] Singleton 模式
更多:[JWorld@TW] [DP]Singleton pattern, Double-checked Locking pattern (by Biologic) [精華]
[University of Maryland]-[Computer Science]-[Bill Pugh] The "Double-Checked Locking is Broken" Declaration
文章標籤
全站熱搜
留言列表