Skip to content

Instantly share code, notes, and snippets.

@mikeb01
Created December 31, 2011 14:26
Show Gist options
  • Save mikeb01/1544126 to your computer and use it in GitHub Desktop.
Save mikeb01/1544126 to your computer and use it in GitHub Desktop.
public long incrementAndGet(AtomicLong atomic) {
long expected;
long updated
do {
expected = atomic.get();
updated = expected + 1;
}
while (!atomic.compareAndSet(expected, updated));
return updated;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment