basically we tend to use ConcuttentHashMap in multi-threading environment. My current code is like this:
ExecutorService executor = Executors.newFixedThreadPool(3);
Map<String, Future<String>> myMap = new HashMap<String, Future<String>>();
myMap.put("SomeValue", executor.submit(() -> return callAndReturnStringMethod("SomeValue"));
myMap.put("AnotheValue", executor.submit(() -> return callAndReturnStringMethod("AnotheValue"));
...
....
I just want to store the future object for the async thread calls corresponding to the passed String as Key in the map.
My first question: Will it be good to use HashMap and not ConcurrentHashMap while dealing with Future object? Should I use ConcurrentHashMap in this scenario? Second question: What could be the trade offs if I use latter one?