All Downloads are FREE. Search and download functionalities are using the official Maven repository.

link.jfire.baseutil.collection.ByteCachePool Maven / Gradle / Ivy

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