Linked Questions

654 votes
19 answers
350k views

What's the difference between ConcurrentHashMap and Collections.synchronizedMap(Map)?

I have a Map which is to be modified by several threads concurrently. There seem to be three different synchronized Map implementations in the Java API: Hashtable Collections.synchronizedMap(Map) ...
Henning's user avatar
  • 11.7k
-1 votes
1 answer
931 views

Difference between Hashtable and ConcurrentHashMap [duplicate]

Can someone elaborate this line briefly? “In Summary ConcurrentHashMap only locked certain portion of Map while Hashtable lock full map while doing iteration”
Shubham Goswami's user avatar
4346 votes
35 answers
1.8m views

What are the differences between a HashMap and a Hashtable in Java?

What are the differences between a HashMap and a Hashtable in Java? Which is more efficient for non-threaded applications?
dmanxiii's user avatar
  • 52.3k
19 votes
3 answers
26k views

ConcurrentHashMap locking

I have read somewhere that in ConcurrentHashMap, the whole map object is not locked and instead a lock is made on a portion of the Map. Can somebody elaborate when does locking come into the picture?...
Anand's user avatar
  • 21.5k
3 votes
3 answers
5k views

locking mechanism used in concurrentHashMap and hashtable

This question was recently asked to me in java interview. I tried to search it later but couldn't find the exact answer. In case if any1 have a link o the answer please let me know. So here goes my ...
sussie's user avatar
  • 33
1 vote
2 answers
2k views

Is it safe to replace all the occurrences of Hashtable with ConcurrentHashmap?

Our legacy multi-threaded application has a lots of usage of Hashtable. Is it safe to replace the Hashtable instances with ConcurrentHashmap instances for performance gain? Will there be any side ...
dpkp's user avatar
  • 13
0 votes
2 answers
2k views

Java- How to create Java Hashtable from HashMap

I want to Create Java Hashtable from HashMap. HashMap hMap = new HashMap(); //populate HashMap hMap.put("1","One"); hMap.put("2","Two"); hMap.put("3","Three"); //create new Hashtable ...
user avatar
0 votes
2 answers
3k views

Java collection framework which does not allow null and allows parallel access

Hashtable does not allow any null as key or value, and Hashtable is legacy and only single thread can access at a time. Which collection class doesn't allow any null and allows concurrent access? ...
surya prakash's user avatar
0 votes
3 answers
722 views

Java and thread safety when creating a cache from scratch

Is the following code thread safe? private static HashMap<String, String> cache = null; public static String getInfo(String key) { populateCache(); return cache.containsKey(key) ? ...
Sayak Banerjee's user avatar
1 vote
1 answer
228 views

Read and write into shared thread variables

first of all i am new to threads and shared variables. So please be kind with me ;-) I'm having a class called Routing. This class recieves and handles messages. If a message is of type A the ...
smsnheck's user avatar
  • 1,593
0 votes
2 answers
54 views

java synchronize collections selection for application requirement

What is synchronized collection means in java . Which to choose for developing application if i am printing records of user in jsp page from servlet?which to choose among the following ...
srinivas's user avatar
  • 472