摘要:
从“最简单”的单例模式说起publicclassSingleton{privatestaticSingletoninstance=null;privatestaticreadonlyobjectsyncRoot=newobject();privateSingleton(){}publicstaticSingletonGetInstance(){if(instance==null){lock(syncRoot){if(instance==null){instance=newSingleton();}}}returninstance;}}lock 确保当一个线程位于代码的临界区时,另一个线程不进入 阅读全文