正数递增器


import java.util.concurrent.atomic.AtomicInteger;

/**
 * @description
 * @author apple
 */
public class PositiveCounter {
    private final AtomicInteger atom;
    private static final int mask = 0xFF;


    public PositiveCounter() {
        atom = new AtomicInteger(0);
    }


    public final int incrementAndGet() {
        final int rt = atom.incrementAndGet();
        return rt & mask;
    }


    public int intValue() {
        return atom.intValue();
    }
}

猜你喜欢

转载自bucketli.iteye.com/blog/1470737