List of usage examples for java.lang.ref SoftReference SoftReference
public SoftReference(T referent)
From source file:com.xpn.xwiki.doc.XWikiDocument.java
public void loadArchive(XWikiContext context) throws XWikiException { if (this.archive == null || this.archive.get() == null) { XWikiDocumentArchive arch = getVersioningStore(context).getXWikiDocumentArchive(this, context); // We are using a SoftReference which will allow the archive to be // discarded by the Garbage collector as long as the context is closed (usually during // the request) this.archive = new SoftReference<XWikiDocumentArchive>(arch); }// w w w. j av a 2s . c om }
From source file:com.xpn.xwiki.doc.XWikiDocument.java
public void setDocumentArchive(XWikiDocumentArchive arch) { // We are using a SoftReference which will allow the archive to be // discarded by the Garbage collector as long as the context is closed (usually during the // request)/*from w ww .ja va 2 s .c o m*/ if (arch != null) { this.archive = new SoftReference<XWikiDocumentArchive>(arch); } }
From source file:uk.ac.ed.epcc.webapp.model.data.Repository.java
/** return the Record cache or null * Even if caching is enabled this may still return null under * heavy memory pressure./*from w ww.j a v a2s . c o m*/ * * @return */ private final Map<Integer, Record> getCache() { if (!use_cache) { return null; } synchronized (this) { if (cache_ref == null || cache_ref.get() == null) { cache_ref = new SoftReference<Map<Integer, Record>>(new HashMap<Integer, Record>()); } // there is a potential race condition here as the reference may be cleared // by the gc between the previous line and the next. return cache_ref.get(); } }
From source file:org.codehaus.groovy.grails.web.util.StreamCharBuffer.java
void addParentBuffer(StreamCharBuffer parent) { if (!notifyParentBuffersEnabled) return;// www .j a v a2 s . c o m if (parentBuffers == null) { parentBuffers = new HashSet<SoftReference<StreamCharBufferKey>>(); } parentBuffers.add(new SoftReference<StreamCharBufferKey>(parent.bufferKey)); }
From source file:org.apache.axis2.jaxws.description.impl.ServiceDescriptionImpl.java
public void setResolvedHandlersDescription(PortInfo portInfo, ResolvedHandlersDescription resolvedHandlersInfo) { // Get the cache and store the handler description Map<PortInfo, ResolvedHandlersDescription> cache = resolvedHandlersDescription.get(); if (cache == null) { cache = new ConcurrentHashMap<PortInfo, ResolvedHandlersDescription>(); resolvedHandlersDescription = new SoftReference<Map<PortInfo, ResolvedHandlersDescription>>(cache); }//w w w .j ava 2 s. c om cache.put(portInfo, resolvedHandlersInfo); }
From source file:com.codename1.impl.android.AndroidImplementation.java
/** * @inheritDoc */ public Object createSoftWeakRef(Object o) { return new SoftReference(o); }
From source file:org.talend.designer.core.model.components.EmfComponent.java
/** * return the common ComponentResourceFactoryImpl to retreive component resource from URI * // ww w .java 2s .c o m * @return factoryImpl */ // here we are using soft references so that whenever the GC runs it can collect the ComponentResourceFactoryImpl private static ComponentResourceFactoryImpl getComponentResourceFactoryImpl() { ComponentResourceFactoryImpl factoryImpl = compResFactorySoftRef == null ? null : compResFactorySoftRef.get(); if (factoryImpl == null) {// if weak ref has not been created or if referenced factory has been GCed then create // a new one factoryImpl = new ComponentResourceFactoryImpl(); compResFactorySoftRef = new SoftReference<ComponentResourceFactoryImpl>(factoryImpl); } return factoryImpl; }
From source file:org.talend.designer.core.model.components.EmfComponent.java
/** * return the common ComponentResourceFactoryImpl to retreive component resource from URI * /*from w w w .j a va2s. co m*/ * @return factoryImpl */ // here we are using soft references so that whenever the GC runs it can collect the ComponentResourceFactoryImpl private static Map getLoadingOptionMap() { Map optionMap = (optionMapSoftRef == null ? null : optionMapSoftRef.get()); if (optionMap == null) {// if weak ref has not been created or if referenced factory has been GCed then create // a new one optionMap = new HashMap(); optionMap.put(XMLResource.OPTION_DEFER_ATTACHMENT, Boolean.TRUE); optionMap.put(XMLResource.OPTION_DEFER_IDREF_RESOLUTION, Boolean.TRUE); optionMap.put(XMLResource.OPTION_USE_PARSER_POOL, new XMLParserPoolImpl()); optionMap.put(XMLResource.OPTION_USE_XML_NAME_TO_FEATURE_MAP, new HashMap()); optionMap.put(XMLResource.OPTION_USE_DEPRECATED_METHODS, Boolean.FALSE); optionMapSoftRef = new SoftReference<Map>(optionMap); } return optionMap; }