List of usage examples for java.util WeakHashMap WeakHashMap
public WeakHashMap()
From source file:org.openmrs.util.HandlerUtil.java
public static void clearCachedHandlers() { cachedHandlers = new WeakHashMap<HandlerUtil.Key, List<?>>(); }
From source file:org.springframework.util.CachingMapDecorator.java
/** * Create a CachingMapDecorator,/*from w w w .jav a 2s . c o m*/ * using an underlying synchronized Map. * @param weakKeys whether to use weak references for keys */ public CachingMapDecorator(boolean weakKeys) { Map internalMap = weakKeys ? (Map) new WeakHashMap() : new HashMap(); this.targetMap = Collections.synchronizedMap(internalMap); }
From source file:net.big_oh.common.web.listener.session.SimpleSessionTrackingListener.java
private static synchronized Map<HttpSession, Object> getSessionsCollectionForServletContext( ServletContext servletContext) { String servletContextKey = getKeyForServletContext(servletContext); Map<HttpSession, Object> sessions = contextToSessionCollectionMap.get(servletContextKey); if (sessions == null) { // Sessions map must be synchronized because multiple threads will // add/remove sessions concurrently. ////from www. j a va2 s. c o m // Sessions map is an instance of WeakHashMap so that this data // structure will never prevent the Session from being garbage // collected. sessions = Collections.synchronizedMap(new WeakHashMap<HttpSession, Object>()); contextToSessionCollectionMap.put(servletContextKey, sessions); } return sessions; }
From source file:sk.stuba.fiit.kvasnicka.qsimsimulation.managers.TopologyManager.java
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject();//www . j a va2 s .c o m edgeCache = new WeakHashMap<CacheKey, Edge>(); }
From source file:org.encuestame.oauth.security.ConcurrentMapOAuthSessionManager.java
/** * Constructor. */ public ConcurrentMapOAuthSessionManager() { sessions = new WeakHashMap<String, StandardOAuthSession>(); }
From source file:io.strandberg.xadisk.XADiskSessionFactory.java
@Autowired public XADiskSessionFactory(JtaTransactionManager jtaTransactionManager, StandaloneFileSystemConfiguration standaloneFileSystemConfiguration) throws InterruptedException { this.transactionManager = jtaTransactionManager.getTransactionManager(); this.standaloneFileSystemConfiguration = standaloneFileSystemConfiguration; xaSessionMap = Collections.synchronizedMap(new WeakHashMap<Transaction, XASession>()); }
From source file:com.adaptris.core.AdaptrisConnectionImp.java
/** * <p>//ww w . j a va2s.c om * Created a new instance. * </p> */ public AdaptrisConnectionImp() { consumers = Collections.newSetFromMap(new WeakHashMap<AdaptrisMessageConsumer, Boolean>()); producers = Collections.newSetFromMap(new WeakHashMap<AdaptrisMessageProducer, Boolean>()); listeners = Collections.newSetFromMap(new WeakHashMap<StateManagedComponent, Boolean>()); state = ClosedState.getInstance(); }
From source file:net.sf.l2j.gameserver.instancemanager.AwayManager.java
private AwayManager() { _awayPlayers = Collections.synchronizedMap(new WeakHashMap<L2PcInstance, RestoreData>()); }
From source file:org.apache.ambari.server.orm.dao.HostConfigMappingDAO.java
private void populateCache() { if (!cacheLoaded) { gl.writeLock().lock();// w w w . ja v a 2 s . com try { gl.writeLock().lock(); try { if (hostConfigMappingByHost == null) { hostConfigMappingByHost = new WeakHashMap<String, Set<HostConfigMapping>>(); TypedQuery<HostConfigMappingEntity> query = entityManagerProvider.get().createQuery( "SELECT entity FROM HostConfigMappingEntity entity", HostConfigMappingEntity.class); List<HostConfigMappingEntity> hostConfigMappingEntities = daoUtils.selectList(query); for (HostConfigMappingEntity hostConfigMappingEntity : hostConfigMappingEntities) { Set<HostConfigMapping> setByHost = hostConfigMappingByHost .get((hostConfigMappingEntity.getHostName())); if (setByHost == null) { setByHost = new HashSet<HostConfigMapping>(); hostConfigMappingByHost.put(hostConfigMappingEntity.getHostName(), setByHost); } HostConfigMapping hostConfigMapping = buildHostConfigMapping(hostConfigMappingEntity); setByHost.add(hostConfigMapping); } } } finally { gl.writeLock().unlock(); } } finally { gl.writeLock().unlock(); } cacheLoaded = true; } }
From source file:org.apache.xml.security.utils.IdResolver.java
/** * Method registerElementById/*from ww w . ja v a2 s.com*/ * * @param element the element to register * @param idValue the value of the ID attribute */ public static void registerElementById(Element element, String idValue) { Document doc = element.getOwnerDocument(); Map<String, WeakReference<Element>> elementMap; synchronized (docMap) { elementMap = docMap.get(doc); if (elementMap == null) { elementMap = new WeakHashMap<String, WeakReference<Element>>(); docMap.put(doc, elementMap); } } elementMap.put(idValue, new WeakReference<Element>(element)); }