Two threads accessing same hashmap, one thread is continuously running other runs after 2 mins and clears that hashmap, how to handle this in java

Viewed 1084

The first thread is of JMS subscriber that listens to a topic. As soon as it gets a message it adds/updates/deletes entries in a hashmap. Another thread runs after every 2 mins using TimerClass and reads the contents of the same hashmap and stores it in a file and clears the hashmap. Please suggest what kind of hashmap- concurrent or synchronized should be used? is there any other way to achieve this ?

4 Answers
Related