
link.jfire.baseutil.collection.ByteCachePool Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jfire-baseutil Show documentation
Show all versions of jfire-baseutil Show documentation
jfire-baseutil is common jar dependency of jfire J2EE package
The newest version!
package link.jfire.baseutil.collection;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
public class ByteCachePool
{
private static Queue queue = new ConcurrentLinkedQueue<>();
/**
* 获取一个cache
*
* @return
*/
public static ByteCache get()
{
ByteCache cache = queue.poll();
if (cache == null)
{
cache = new ByteCache();
}
return cache;
}
/**
* 归还使用的cache
*
* @param cache
*/
public static void returnCache(ByteCache cache)
{
cache.clear();
queue.offer(cache);
}
/**
* 缩小当前的缓存池
*/
public static void shink()
{
queue.clear();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy