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 FactorialCalculator. Specify that it implements the Callable interface parameterized by the Integer type:
        public class FactorialCalculator implements Callable<Integer> {
  1. Declare a private Integer attribute called number to store the number that this task will use for its calculations:
        private final Integer number;
  1. Implement the constructor of the class that initializes the attribute of the class:
        public FactorialCalculator(Integer number){           this.number=number;         }
  1. Implement the call() method. This method returns the factorial of the number attribute of FactorialCalculator:
        @Override         public Integer call() throws Exception {
  1. First, create and ...

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