How it works...

The key to this example is in the Account class. In this class, we declared an AtomicLong variable named balance to store the balance of the account, a LongAdder variable named operations to store the number of operations we made with the account, and a DoubleAccumulator variable named commission to store the value of the commissions of the operations. In the constructor of the commission object, we specified that the value will be incremented with the expression 0.2*y. With this, we wanted to specify that we will increment the actual value of the variable with the result of its multiplication by 0.2 and the value of the parameter we pass to the accumulate() method.

To implement the getBalance() method that returns the value ...

Get Java 9 Concurrency Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.