Java 8 SoftReference - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 SoftReference class.

This code example shows how to use the following methods:get
 
    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);
9
CodeRank
This code example shows how to use the following methods:
        super(delegate); 
    } 
 
    @Override 
    Reference<V> fold(V value) { 
        return new SoftReference<V>(value); 
    } 
 
} 
8
CodeRank
This code example shows how to use the following methods:
        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;
8
CodeRank
This code example shows how to use the following methods:
    } 
 
    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);
8
CodeRank
This code example shows how to use the following methods:
  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;
  } 
} 
8
CodeRank
This code example shows how to use the following methods:
	} 
 
	public V put(K key, V value) {
		lock.lock();
		try { 
			map.put(key, new SoftReference<V>(value, queue));
			return value;
		} finally { 
			lock.unlock();
		} 
	} 
 
	public V get(K key) {
		lock.lock();
		try { 
			queue.poll();
			return map.get(key).get();
		} finally { 
			lock.unlock();
		} 
7
CodeRank
This code example shows how to use the following methods:
  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;
  } 
} 
8
CodeRank
This code example shows how to use the following methods:
 
        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(); 
    } 
} 
7
CodeRank
This code example shows how to use the following methods:
        super(delegate); 
    } 
 
    @Override 
    Reference<V> fold(V value) { 
        return new SoftReference<V>(value); 
    } 
 
} 
7
CodeRank
This code example shows how to use the following methods:
      if (reference != null) {
        System.out.println("[DEBUG] ********************* GC'ed SdkEnvironment reused!");
      } 
 
      sdkEnvironment = factory.create();
      sdkToEnvironmentSoft.put(sdkConfig, new SoftReference<SdkEnvironment>(sdkEnvironment));
    } 
 
    return sdkEnvironment;
  } 
} 
7
CodeRank

Other Java 8 SoftReference Examples

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:

Read More

See Code Examples for Java 8 SoftReference Methods: