List of usage examples for java.lang.ref SoftReference SoftReference
public SoftReference(T referent)
From source file:de.undercouch.bson4jackson.io.StaticBuffers.java
/** * @return a thread-local singleton instance of this class *///w ww . jav a2s . co m public static StaticBuffers getInstance() { SoftReference<StaticBuffers> ref = _instance.get(); StaticBuffers buf = (ref == null ? null : ref.get()); if (buf == null) { buf = new StaticBuffers(); _instance.set(new SoftReference<StaticBuffers>(buf)); } return buf; }
From source file:org.jboss.windup.metadata.type.ManifestMetadata.java
public Manifest getManifest() { if (manifest == null) { // create it. try {/*from w ww. j av a2s .c o m*/ if (LOG.isDebugEnabled()) { LOG.debug("Reading manifest: " + filePointer.getAbsolutePath()); } Manifest mTmp = new Manifest(new FileInputStream(filePointer)); manifest = new SoftReference<Manifest>(mTmp); LOG.debug("Reading manifest complete."); } catch (Exception e) { LOG.error("Bad Manifest? " + filePointer.getAbsolutePath()); LOG.info("Skipping file. Continuing Windup Processing..."); Summary sr = new Summary(); sr.setDescription("Bad Manifest? Unable to parse."); sr.setLevel(NotificationLevel.CRITICAL); sr.setEffort(new UnknownEffort()); this.getDecorations().add(sr); this.manifest = null; } } if (manifest == null) { return null; } return manifest.get(); }
From source file:edu.ksu.cis.santos.mdcf.dml.ast.AstNode.java
/** * Retrieves the immediate children of this AST. * // w w w . ja va 2s. co m * @return a possibly empty array of this node's children. The returned array * can be mutated but it does not affect the AST. */ public final Object[] children() { Object[] result = null; if ((this._children == null) || ((result = this._children.get()) == null)) { result = getChildren(); this._children = new SoftReference<Object[]>(result); } return result; }
From source file:com.achep.acdisplay.notifications.Action.java
@NonNull @TargetApi(Build.VERSION_CODES.JELLY_BEAN) private static Factory getFactory() { Factory factory = sFactoryRef.get(); if (factory == null) { if (Device.hasKitKatWatchApi()) { factory = new FactoryKitKatWatch(); } else {/*w w w . j a va 2s. co m*/ factory = Device.hasKitKatApi() ? new FactoryKitKat() : new FactoryJellyBean(); } sFactoryRef = new SoftReference<>(factory); return factory; } return factory; }
From source file:mobisocial.musubi.ui.util.EmojiSpannableFactory.java
public static EmojiSpannableFactory getInstance(Context context) { if (sSpannableFactory != null) { EmojiSpannableFactory f = sSpannableFactory.get(); if (f != null) { return f; }// www . j av a 2 s. c o m } EmojiSpannableFactory f = new EmojiSpannableFactory(context); sSpannableFactory = new SoftReference<EmojiSpannableFactory>(f); return f; }
From source file:net.femtoparsec.jnlmin.utils.PropertySetter.java
public static PropertySetter getPropertySetter(Class beanClass) { cleanCache();/*from w ww. j av a 2s . c o m*/ Reference<PropertySetter> reference = CACHE.get(beanClass); PropertySetter result = reference == null ? null : reference.get(); if (result == null) { result = new PropertySetter(beanClass); CACHE.put(beanClass, new SoftReference<PropertySetter>(result)); } return result; }
From source file:com.splunk.shuttl.archiver.archive.ArchiveConfiguration.java
public static ArchiveConfiguration getSharedInstance() { ArchiveConfiguration sharedInstance = null; if (sharedInstanceRef != null) sharedInstance = sharedInstanceRef.get(); if (sharedInstance == null) { sharedInstance = createConfigurationFromMBean(); sharedInstanceRef = new SoftReference<ArchiveConfiguration>(sharedInstance); }/* w ww .ja v a 2s. c o m*/ return sharedInstance; }
From source file:net.sf.ehcache.distribution.EventMessageTest.java
/** * SoftReference behaviour testing.//from w w w.ja v a2 s . c o m */ public void testSoftReferences() { AbstractCacheTest.forceVMGrowth(); Map map = new HashMap(); for (int i = 0; i < 100; i++) { map.put(new Integer(i), new SoftReference(new byte[1000000])); } int counter = 0; for (int i = 0; i < 100; i++) { SoftReference softReference = (SoftReference) map.get(new Integer(i)); byte[] payload = (byte[]) softReference.get(); if (payload != null) { LOG.info("Value found for " + i); counter++; } } //This one varies by operating system and architecture. assertTrue("You should get more than " + counter + " out of SoftReferences", counter >= 13); }
From source file:syndeticlogic.memento.Reaper.java
public Reaper(Cache cache) { this.toString = cache.toString(); this.reference = new SoftReference<Cache>(cache); }
From source file:com.lrs.enviroment.Metadata.java
/** * @return the metadata for the current application *///w ww.j a v a2s. co m public static Metadata getCurrent() { Metadata m = getFromMap(); if (m == null) { m = new Metadata(); holder.set(new SoftReference<Metadata>(m)); } return m; }