Tuesday 29 December 2015

Implementing thread safety using ConcurrentHashMap


When your program can be accessed by multiple threads concurrently, you need to ensure that it is thread-safe. 
Stateless objects which do not share any state between the method calls are always thread-safe. However, when the state is shared across multiple methods of a class and multiple threads can call these methods concurrently then you need to take explicit measures to ensure thread safety.