List of usage examples for java.lang.ref SoftReference SoftReference
public SoftReference(T referent)
From source file:Main.java
public static void showToast(final Context context, Toast toast, final String s) { if (Looper.getMainLooper() == Looper.myLooper()) { hideToast();/*from w ww . j a v a2s .co m*/ toast.show(); sToastRef = new SoftReference<Toast>(toast); } else { if (context instanceof Activity) { ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { showToast(context, s); } }); } } }
From source file:Main.java
public static BitmapDrawable getBitmapDrawable(Context context, Uri uri) { System.out.println("uri path = " + uri.getPath()); Bitmap b;//from w w w . j a v a 2s. co m try { String path = uri.getPath(); if (mCache.containsKey(path)) { BitmapDrawable d = mCache.get(path).get(); if (d != null) { System.out.println("not recycle path = " + uri.getPath()); return d; } else { System.out.println("be recycle path = " + uri.getPath()); mCache.remove(path); } } System.out.println("----->safeDecodeStream start"); b = safeDecodeStream(context, uri, 60, 60); System.out.println("----->safeDecodeStream end"); final BitmapDrawable bd = new BitmapDrawable(b); mCache.put(path, new SoftReference<BitmapDrawable>(bd)); return bd; } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:Main.java
public synchronized static ResourceBundle loadBundle(String resource) { if (sRefMap == null) { sRefMap = new HashMap<String, SoftReference<ResourceBundle>>(); }//from ww w.jav a2s. c om SoftReference<ResourceBundle> bundleRef = sRefMap.get(resource); if (bundleRef == null || bundleRef.get() == null) { // Attempt to load the messages. try { ResourceBundle bundle = setLocale(Locale.getDefault(), resource); bundleRef = new SoftReference<ResourceBundle>(bundle); sRefMap.put(resource, bundleRef); return bundle; } catch (Throwable e) { //Logger.global.warning("Got Throwable " + e + " loading messages"); return null; } } else { return bundleRef.get(); } }
From source file:com.locadz.HttpClientFactory.java
/** * Get a client instance. <br/>/* w w w . ja va 2s. c om*/ * Note: You should not assign the instance to a class variable. * @return a HttpClient instance. */ public static final HttpClient getInstance() { ReentrantReadWriteLock.ReadLock readLock = lock.readLock(); try { readLock.lock(); HttpClient httpClient = instance.get(); if (httpClient == null) { readLock.unlock(); lock.writeLock().lock(); httpClient = instance.get(); if (httpClient == null) { httpClient = new DefaultHttpClient(); instance = new SoftReference<HttpClient>(httpClient); } readLock.lock(); lock.writeLock().unlock(); } return httpClient; } finally { readLock.unlock(); } }
From source file:Main.java
public static XPathExpression getXPathExpression(String xPathString) throws XPathExpressionException { SoftReference<XPathExpression> ref = xPathExpressionsCache.get(xPathString); XPathExpression expression = ref == null ? null : ref.get(); if (expression == null) xPathExpressionsCache.put(xPathString, new SoftReference<XPathExpression>(expression = getSharedXPath().compile(xPathString))); return expression; }
From source file:com.gzj.tulip.load.RoseScanner.java
public synchronized static RoseScanner getInstance() { if (softReference == null || softReference.get() == null) { RoseScanner roseScanner = new RoseScanner(); softReference = new SoftReference<RoseScanner>(roseScanner); }// w ww .j av a 2 s . c o m return softReference.get(); }
From source file:com.sinosoft.one.mvc.scanning.MvcScanner.java
public synchronized static MvcScanner getInstance() { if (softReference == null || softReference.get() == null) { MvcScanner mvcScanner = new MvcScanner(); softReference = new SoftReference<MvcScanner>(mvcScanner); }/* w w w . j av a 2 s .c o m*/ return softReference.get(); }
From source file:ch.ralscha.extdirectspring.util.ApiCache.java
public void put(ApiCacheKey key, String apiString) { cache.put(key, new SoftReference<String>(apiString)); }
From source file:SoftCache.java
public Object put(Object key, Object value) { SoftReference softRef = (SoftReference) map.put(key, new SoftReference(value)); if (softRef == null) return null; Object oldValue = softRef.get(); softRef.clear();// w ww .j a v a 2s . c o m return oldValue; }
From source file:com.laxser.blitz.scanning.BlitzScanner.java
public synchronized static BlitzScanner getInstance() { if (softReference == null || softReference.get() == null) { BlitzScanner blitzScanner = new BlitzScanner(); softReference = new SoftReference<BlitzScanner>(blitzScanner); }/*from w w w.j ava2 s . co m*/ return softReference.get(); }