Implementation of alternatives with concurrent programming
Most of the examples we have implemented through the chapters of this book can be implemented using other components of the Java concurrency API. In this section, we will describe how to implement some of these alternatives.
The k-nearest neighbors' algorithm
You have implemented the k-nearest neighbors' algorithm in Chapter 2, Managing Lots of Threads – Executors, using an executor. This is a simple machine-learning algorithm used for supervised classification. You have a training set of previous classified examples. To obtain the class of a new example, you calculate the distance from this example to the training set of examples. The majority of classes in the nearest examples are the classes selected for the example. You can also implement this algorithm with one of the following components of the concurrency API:
Threads: You can implement this example using
Thread
objects. You have to execute the tasks executed in the executor...