Code example for AtomicInteger

Methods: addAndGet, get

0
    public void returnBuffer(XByteBuffer buffer) {
        if ( (size.get() + buffer.getCapacity()) <= maxSize ) {
            size.addAndGet(buffer.getCapacity());
            queue.offer(buffer);
        } 
    } 
 
    public void clear() { 
        queue.clear();
        size.set(0);
    } 
 
    public int getMaxSize() { 
        return maxSize;
    } 
 
}