These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 SoftReference class.
private static final ThreadLocal<SoftReference<Entry>> cache = new ThreadLocal<SoftReference<Entry>>(); static Entry instance() { SoftReference<Entry> ref = cache.get(); Entry entry = ref == null ? null : ref.get(); if (entry == null) { HandlesStreamInput handles = new HandlesStreamInput(); entry = new Entry(handles); cache.set(new SoftReference<Entry>(entry)); } return entry; } public static void clear() { cache.remove(); } public static StreamInput compressed(Compressor compressor, StreamInput in) throws IOException { return compressor.streamInput(in);
super(delegate); } @Override Reference<V> fold(V value) { return new SoftReference<V>(value); } }
SoftReference<Entry> ref = cache.get(); Entry entry = ref == null ? null : ref.get(); if (entry == null) { HandlesStreamInput handles = new HandlesStreamInput(); entry = new Entry(handles); cache.set(new SoftReference<>(entry)); } return entry; } public static void clear() { cache.remove(); } public static StreamInput compressed(Compressor compressor, StreamInput in) throws IOException { return compressor.streamInput(in); } public static HandlesStreamInput cachedHandles(StreamInput in) { HandlesStreamInput handles = instance().handles;
} V v0 = lookup(key); // updates position if (v0 != null) { // update map entry map.put(key, new SoftReference<V>(val)); // (if same, nothing changes) return v0; } SoftReference<V> ret = null; // if too big, evict if (fifo.size() >= maxsize) { K kOut = fifo.removeFirst(); ret = map.get(kOut); map.remove(kOut); } // install new pair fifo.addLast(key);
private static ResourceBundle getBundle() { ResourceBundle bundle = null; if (ourBundle != null) bundle = ourBundle.get(); if (bundle == null) { bundle = ResourceBundle.getBundle(PATH_TO_BUNDLE); ourBundle = new SoftReference<ResourceBundle>(bundle); } return bundle; } }
private static ResourceBundle getBundle() { ResourceBundle bundle = null; if (ourBundle != null) bundle = ourBundle.get(); if (bundle == null) { bundle = ResourceBundle.getBundle(PATH_TO_BUNDLE); ourBundle = new SoftReference<ResourceBundle>(bundle); } return bundle; } }
return bitmap; } public void put(String url, Bitmap bitmap) { mSoftCache.put(url, new SoftReference<Bitmap>(bitmap)); } public void flush() { mSoftCache.clear(); } public void onLowMemoryReceived() { flush(); } }
super(delegate); } @Override Reference<V> fold(V value) { return new SoftReference<V>(value); } }
if (reference != null) { System.out.println("[DEBUG] ********************* GC'ed SdkEnvironment reused!"); } sdkEnvironment = factory.create(); sdkToEnvironmentSoft.put(sdkConfig, new SoftReference<SdkEnvironment>(sdkEnvironment)); } return sdkEnvironment; } }
12: if(!cache.containsKey(id))
13: return null;
14: SoftReference<Bitmap> ref=cache.get(id);
15: return ref.get();
16: }
-
17:
18: public void put(String id, Bitmap bitmap){
19: cache.put(id, new SoftReference<Bitmap>(bitmap));
20: }
21: