當前位置: 首頁>>代碼示例>>Java>>正文


Java SoftReference.clear方法代碼示例

本文整理匯總了Java中java.lang.ref.SoftReference.clear方法的典型用法代碼示例。如果您正苦於以下問題:Java SoftReference.clear方法的具體用法?Java SoftReference.clear怎麽用?Java SoftReference.clear使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.lang.ref.SoftReference的用法示例。


在下文中一共展示了SoftReference.clear方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getDirectByteBuffer

import java.lang.ref.SoftReference; //導入方法依賴的package包/類
private static ByteBuffer getDirectByteBuffer()
{
    // Since direct buffers are allocated outside of the heap they can behave strangely in relation to GC
    // So we try to make them as long-lived as possible and cache them in a ThreadLocal
    ByteBuffer buffer = null;
    int blockSize = getBlockSize();
    SoftReference<ByteBuffer> reference = DiskDataStorage.threadLocal.get();
    if (reference != null)
    {
        buffer = reference.get();
        if (buffer != null && buffer.capacity() != blockSize)
        {
            // Clear references to the direct buffer so it may be GC'd
            reference.clear();
            buffer = null;
        }
    }
    if (buffer == null)
    {
        buffer = ByteBuffer.allocateDirect(blockSize);
        reference = new SoftReference<ByteBuffer>(buffer);
        DiskDataStorage.threadLocal.set(reference);
    }

    return buffer;
}
 
開發者ID:mtommila,項目名稱:apfloat,代碼行數:27,代碼來源:DiskDataStorage.java

示例2: closeOldLoaders

import java.lang.ref.SoftReference; //導入方法依賴的package包/類
private void closeOldLoaders() throws IOException {
    SoftReference<Closeable> ref = loadersToClose.poll();
    while (ref != null) {
        Closeable closeable = ref.get();
        if (closeable != null) {
            closeable.close();
        }
        ref.clear();
        ref = loadersToClose.poll();
    }
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:12,代碼來源:DefaultVersionedPlayRunAdapter.java

示例3: put

import java.lang.ref.SoftReference; //導入方法依賴的package包/類
public AnyObject put(Long key, AnyObject value) {
    SoftReference<AnyObject> softReference = cacheMap.put(key, new SoftReference<>(value));

    if (softReference != null) {
        AnyObject o = softReference.get();
        softReference.clear();
        return o;
    } else {
        return null;
    }
}
 
開發者ID:avedensky,項目名稱:JavaRushTasks,代碼行數:12,代碼來源:SoftCache.java

示例4: remove

import java.lang.ref.SoftReference; //導入方法依賴的package包/類
public AnyObject remove(Long key) {
    SoftReference<AnyObject> softReference = cacheMap.remove(key);

    //напишите тут ваш код
    if (softReference != null) {
        AnyObject o = softReference.get();
        softReference.clear();
        return o;
    } else {
        return null;
    }
}
 
開發者ID:avedensky,項目名稱:JavaRushTasks,代碼行數:13,代碼來源:SoftCache.java

示例5: makeImage

import java.lang.ref.SoftReference; //導入方法依賴的package包/類
private static SoftReference<CachedImage> makeImage(CachedTeXFormula cached)
		throws ParseException {
	TeXFormula formula = new TeXFormula(cached.f);
	TeXIcon icon = formula.createTeXIcon(cached.style, cached.size,
			cached.type, cached.fgcolor);
	icon.setInsets(new Insets(cached.inset, cached.inset, cached.inset,
			cached.inset));
	Bitmap image = Bitmap.createBitmap(icon.getIconWidth(),
			icon.getIconHeight(), Config.ARGB_8888);
	Canvas g2 = new Canvas(image);
	icon.paintIcon(g2, 0, 0);
	cached.setDimensions(icon.getIconWidth(), icon.getIconHeight(),
			icon.getIconDepth());
	SoftReference<CachedImage> img = new SoftReference<CachedImage>(
			new CachedImage(image, cached), queue);

	if (cache.size() >= max) {
		Reference soft;
		while ((soft = queue.poll()) != null) {
			CachedImage ci = (CachedImage) soft.get();
			if (ci != null) {
				cache.remove(ci.cachedTf);
			}
		}
		Iterator<CachedTeXFormula> iter = cache.keySet().iterator();
		if (iter.hasNext()) {
			CachedTeXFormula c = iter.next();
			SoftReference<CachedImage> cachedImage = cache.get(c);
			if (cachedImage != null) {
				cachedImage.clear();
			}
			cache.remove(c);
		}
	}
	cache.put(cached, img);

	return img;
}
 
開發者ID:daquexian,項目名稱:FlexibleRichTextView,代碼行數:39,代碼來源:JLaTeXMathCache.java

示例6: flush

import java.lang.ref.SoftReference; //導入方法依賴的package包/類
/**
 * Flushes the cached object.  Forces the next invocation of get() to
 * invoke reconstitute().
 */
public synchronized void flush() {
    SoftReference s = soft;
    if (s != null) s.clear();
    soft = null;
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:10,代碼來源:Ref.java

示例7: flush

import java.lang.ref.SoftReference; //導入方法依賴的package包/類
/**
 * Flushes the cached object.  Forces the next invocation of get() to
 * invoke reconstitute().
 */
public synchronized void flush() {
    SoftReference<Image> s = soft;
    if (s != null) s.clear();
    soft = null;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:10,代碼來源:AppletImageRef.java


注:本文中的java.lang.ref.SoftReference.clear方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。