In this recipe, we implemented an application that uses ConcurrentHashMap to store information about operations made by users. Internally, the hash table uses the user attribute of the Operation class as a key and ConcurrentLinkedDeque (a non-blocking concurrent list) as its value to store all the operations associated with that user.
First, we filled the hash with some random data using 10 different threads. We implemented the HashFiller task for this purpose. The biggest problem with these tasks is what happens when you have to insert a key in the hash table. If two threads want to add the same key at the same time, you can lose the data inserted by one of the threads and have a data-race condition. To solve this problem, ...