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

Get Mastering Concurrency Programming with Java 8 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.