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

com.firefly.net.buffer.ThreadSafeIOBufferPool Maven / Gradle / Ivy

There is a newer version: 5.0.0-dev6
Show newest version
package com.firefly.net.buffer;

import com.firefly.net.BufferPool;

import java.nio.ByteBuffer;

public class ThreadSafeIOBufferPool implements BufferPool {

    private final ThreadLocal safeBufferPool;

    public ThreadSafeIOBufferPool() {
        this(true);
    }

    public ThreadSafeIOBufferPool(boolean directBuffer) {
        safeBufferPool = ThreadLocal.withInitial(() -> new IOBufferPool(directBuffer));
    }

    @Override
    public final ByteBuffer acquire(int size) {
        return safeBufferPool.get().acquire(size);
    }

    @Override
    public final void release(ByteBuffer buffer) {
        safeBufferPool.get().release(buffer);
    }

    @Override
    public int size() {
        return safeBufferPool.get().size();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy