-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Java 9 Concurrency Cookbook, Second Edition
By :

When you execute the ForkJoinTask
objects in a ForkJoinPool
class, you can cancel them before they start their execution. The ForkJoinTask
class provides the cancel()
method for this purpose. There are some points you have to take into account when you want to cancel a task, which are as follows:
ForkJoinPool
class doesn't provide any method to cancel all the tasks it has running or waiting in the poolIn this recipe, you will implement an example of the cancellation of ForkJoinTask
objects. You will look for the position of a number in an array. The first task that finds the number will cancel the remaining tasks. As that functionality is not provided by the fork/join framework, you will implement an auxiliary class to do this cancellation.
The example of this recipe has been implemented using the Eclipse IDE. If you use Eclipse or other IDE such as NetBeans, open it and create a new...