当前位置: 首页>>代码示例>>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;未经允许,请勿转载。