Search in sources :

Example 1 with SimplyByteBufAllocator

use of com.generallycloud.baseio.buffer.SimplyByteBufAllocator in project baseio by generallycloud.

the class TestSimplyByteBufAllocator method main.

public static void main(String[] args) throws Exception {
    int capacity = 100;
    int unit = 1;
    int max = unit * capacity / 5;
    allocator = new SimplyByteBufAllocator(capacity, unit, false);
    // allocator = new SimpleByteBufAllocator(capacity, unit, false);
    allocator.start();
    Runnable r = () -> {
        for (; ; ) {
            int random = new Random().nextInt(max);
            if (random == 0) {
                continue;
            }
            ByteBuf buf = allocator.allocate(random);
            if (buf == null) {
                System.out.println(buf + Thread.currentThread().getName());
            }
            ThreadUtil.sleep(new Random().nextInt(20));
            ReleaseUtil.release(buf);
            // String des = allocator.toString();
            // 
            // if (des.indexOf("free=100") == -1) {
            // System.out.println();
            // }
            // ThreadUtil.sleep(10);
            debug();
        }
    };
    ThreadUtil.execute(r);
    ThreadUtil.execute(r);
// ThreadUtil.execute(r);
// 
// ThreadUtil.execute(r);
}
Also used : SimplyByteBufAllocator(com.generallycloud.baseio.buffer.SimplyByteBufAllocator) Random(java.util.Random) ByteBuf(com.generallycloud.baseio.buffer.ByteBuf)

Aggregations

ByteBuf (com.generallycloud.baseio.buffer.ByteBuf)1 SimplyByteBufAllocator (com.generallycloud.baseio.buffer.SimplyByteBufAllocator)1 Random (java.util.Random)1