How to do it...

Follow these steps to implement the example:

  1. Create a class named Account with two double public attributes named amount and unsafeAmount. Implement the constructor to initialize its values:
        public class Account {           public double amount;           public double unsafeAmount;                    public Account() {             this.amount=0;             this.unsafeAmount=0;           }         }
  1. Create a class named Decrementer and specify that it implements the Runnable interface. It has a private Account attribute initialized in the constructor of the class:
        public class Decrementer implements Runnable {            private Account account;           public Decrementer(Account account) {             this.account = account;           }
  1. Implement the run() method. This method will make 10,000 decrement operations in the ...

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.