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

In this recipe, we implemented a Task class to store Contact objects in a navigable map. Each contact has a name, which is the ID of the task that creates it, and a phone number, which is a number between 1,000 and 2,000. We concatenated these values as keys for the contacts. Each Task object creates 1,000 contacts; these contacts are stored in the navigable map using the put() method.

If you insert an element with a key that exists in the map, the element associated with that key will be replaced by the new element.

The main() method of the Main class creates 26 Task objects, using the letters between A and Z as IDs. Then, you used some methods to obtain data from the map. The firstEntry() method returns a Map.Entry object ...

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