In the returnFG() method, we are creating a new FutureGroup with this instruction:
FutureGroup<int> futureGroup = FutureGroup<int>();
A FutureGroup is a generic, so FutureGroup<int> means that the values returned inside the FutureGroup will be of type int.
The add method allows you to add several Futures in a FutureGroup. In our example, we added add three Futures:
futureGroup.add(returnOneAsync());
futureGroup.add(returnTwoAsync());
futureGroup.add(returnThreeAsync());
Once all the Futures have been added, you always need to call the close method. This tells the framework that all the futures have been added, and the tasks are ready to be run:
futureGroup.close();
In order to read the values returned by the collection of Futures, you can leverage the then() method of the future property of the FutureGroup. The returned values are placed in a List, so you can use a forEach loop to read the values. You can also call the setState() method...