O'Reilly logo

Java 9 Concurrency Cookbook - Second Edition by Javier Fernández González

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required