cachemanagerimpl.java
来自「JAVA Servlet2.3外文书籍源码」· Java 代码 · 共 73 行
JAVA
73 行
package cache;import java.util.HashMap;import java.util.Iterator;public final class CacheManagerImpl implements ICacheManager { private static CacheManagerImpl mySelf; private HashMap cacheMap = new HashMap();
/** @link aggregation */
/*#SimpleCacheImpl lnkSimpleCacheImpl;*/
private CacheManagerImpl() { Thread th = new Thread(new Runnable() { public void run() { try { Thread.sleep(60*1000); }catch(InterruptedException ex) { throw new RuntimeException(ex.getMessage()); } expire(); } }); th.setPriority(th.MIN_PRIORITY); th.start(); } public static ICacheManager getInstance() { if(mySelf == null) { synchronized(ICacheManager.class) { if(mySelf == null) mySelf = new CacheManagerImpl(); } } return mySelf; } public ICache getCache(String cacheName) { synchronized(this) { return (ICache)cacheMap.get(cacheName); } } public void addCache(ICache cache) { synchronized(this) { cacheMap.put(cache.getName(), cache); } } private void expire() { synchronized(this) { Iterator it = cacheMap.values().iterator(); while(it.hasNext()) ((ICache)it.next()).expire(); } } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?