單利模式

採用內部類實現單利模式java

public class CacheClient {
	private   CacheClient(){
	}
	/**
	 * 單利模式 經過內部類 實現。
	 *   	一、能夠實現延遲加載。
	 *   	二、不用使用 synchronized 關鍵字。
	 */
	private static class CacheHolder{
		private static	CacheClient instance = new  CacheClient();
	}
	
	public static   CacheClient getInstance(){
		return CacheHolder.instance;
	}
}
相關文章
相關標籤/搜索