Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.ning.compress.lzf.parallel;
 

Author(s):
C├ędrik LIME
 
 class BlockManager {
    /* used as a blocking Stack (FIFO) */
    private final BlockingDeque<byte[]> blockPool;
    public BlockManager(int blockPoolSizeint blockSize) {
//        log.debug("Using block pool size of " + blockPoolSize);
         = new LinkedBlockingDeque<byte[]>(blockPoolSize);
        for (int i = 0; i < blockPoolSize; ++i) {
            .addFirst(new byte[blockSize]);
        }
    }
    public byte[] getBlockFromPool() {
        byte[] block = null;
        try {
            block = .takeFirst();
        } catch (InterruptedException e) {
        	throw new RuntimeException(e);
        }
        return block;
    }
    public void releaseBlockToPool(byte[] block) {
        assert ! .contains(block);
//        Arrays.fill(block, (byte)0);
        try {
            .putLast(block);
        } catch (InterruptedException e) {
        	throw new RuntimeException(e);
        }
    }
New to GrepCode? Check out our FAQ X