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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access