private ByteBuffer getBuffer(final int minCapacity) {
        // This method is called a LOT so needs to be performant

        ByteBuffer buffer = null;
        int count = 0;
        boolean isNewBuffer = false;
        while (buffer == null) {
            count++;
            // Loop over all queues with capacity >= minCapacity, starting with smallest
            for (final Queue<ByteBuffer> bufferQueue : bufferQueueMap.tailMap(minCapacity).values()) {
                buffer = bufferQueue.poll();
                if (buffer != null) {
                    break; // out of for loop
                }
            }

            if (buffer == null) {
                // Looked in all queues and found nothing
                if (minCapacity > largestBufferInPool.get() || totalPooledCapacity.get() < MAX_BYTES_IN_POOL) {
                    // if we are trying to get a buffer bigger than anything in the pool then
                    // there is no point in going round again.
                    buffer = createNewBuffer(minCapacity);
                    isNewBuffer = true;
                }
            }
            // if buffer is still null then our pool is at capacity so we just loop round again
            // as another thread should have released one.
        }

//        if (LOGGER.isDebugEnabled()) {
//            if (count > 1) {
//                LOGGER.debug("Obtained {} buffer after {} iterations", (isNewBuffer ? "new" : "pooled"), count);
//            }
//            getCount.incrementAndGet();
//            requestsMap.computeIfAbsent(minCapacity, k -> new AtomicInteger(0))
//                    .incrementAndGet();
//        }
        return buffer;
    }
An unbounded self-populating pool of directly allocated ByteBuffers.
When using one of the methods to get/use a buffer from the pool the
smallest available buffer that is greater than or equal to the required
capacity will be provided. All buffers will be cleared on return to
the pool.
<p>
As this pool is un-bounded it could grow very large under high contention
<p>
This impl uses a {@link ConcurrentSkipListMap} keyed on capacity with a ConQ
with no synchronisation.
stroom-bytebuffer/src/main/java/stroom/bytebuffer/ByteBufferPoolImpl2.java