单利模式

采用内部类实现单利模式java

public class CacheClient {
	private   CacheClient(){
	}
	/**
	 * 单利模式 经过内部类 实现。
	 *   	一、能够实现延迟加载。
	 *   	二、不用使用 synchronized 关键字。
	 */
	private static class CacheHolder{
		private static	CacheClient instance = new  CacheClient();
	}
	
	public static   CacheClient getInstance(){
		return CacheHolder.instance;
	}
}
相关文章
相关标签/搜索