AtomicLong examples

new AtomicLong().get(); // default 0
new AtomicLong().incrementAndGet(); // 1
new AtomicLong().addAndGet(2L); // 2
new AtomicLong(3L).updateAndGet(n -> n * n); // 9
new AtomicLong(3L).accumulateAndGet(2, (n,x) -> n * x); // 6

Supports lock-less atomic operations

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s