Why is there no ConcurrentLinkedHashMap class in jdk?

This question follows directly from my previous question here at SO . I think the answer to my second question is no. So I would like to understand why there is no ConcurrentLinkedHashMap in the java.util.concurrent package? I mean there is a ConcurrentHashMap, but no ConcurrentLinkedHashMap. Doesn't it make any sense to have such a class in parallel environments? I mean, what is the main technical reason here for its lack of availability? Is there something similar in Guava / Apache Commons?

+4
source share
3 answers

Why is there no ConcurrentLinkedHashMap class in jdk?

You will need to ask the guys from Oracle Java, but I think this is a combination:

  • the perception that few people need it, and
  • inherent difficulties in implementing data structures with good performance characteristics in situations with a high degree of parallelism.

In this case, it seems to me that implementing the collection class so that iterating the key / value / record sets is not a concurrency bottleneck would be ... um ... difficult. (And even if people came up with a way to do this, it remains a fact that designing and implementing and proving the validity of general parallel structures and general purpose algorithms is difficult.)

+6
source
#define PERSONAL_OPINION 

From a design point of view, it makes sense to always use

 Map m = Collections.synchronizedMap(new HashMap()); ... Set s = m.keySet(); // Needn't be in synchronized block ... synchronized(m) { // Synchronizing on m, not s! Iterator i = s.iterator(); // Must be in synchronized block while (i.hasNext()) foo(i.next()); } 

example in synchronizedMap

Why? Since the synchronization mechanism is tied to high abstraction ( Map interface). But assuming I'm right, there may be two reasons still having ConcurrentHashMap :

  • There is a ConcurrentHashMap front of this synchronization engine.
  • Or there is a performance boost when creating a specific synchronized mechanism.

My point in an ideal world of design, even ConcurrentHashMap should not exist.

 #end //personal opinion 
+2
source

Source: https://habr.com/ru/post/1432713/


All Articles