Java tutorial
//package com.java2s; import java.util.concurrent.atomic.AtomicLong; public class Main { public static long getAndAddRequest(AtomicLong atomiclong, long l) { long l1; do { l1 = atomiclong.get(); } while (!atomiclong.compareAndSet(l1, addCap(l1, l))); return l1; } public static long addCap(long l, long l1) { l1 = l + l1; l = l1; if (l1 < 0L) { l = 0x7fffffffffffffffL; } return l; } }