Code example for AtomicInteger

Methods: set

0
        reset(); 
    } 
 
    private void reset() { 
        readIndex.set(0);
        writeIndex.set(0);
    } 
 
    private AtomicInteger readIndex = new AtomicInteger();
    private AtomicInteger writeIndex = new AtomicInteger();
     
    public void add(byte value) {
        array[writeIndex.getAndIncrement()] = value;
    } 
 
    public byte get() { 
        if (size() <= 0) 
            return -1; 
 
        byte outcomingByte = array[readIndex.getAndIncrement()];