Java Concurrent HashMap

I want to convert ConcurrentHashMap to TreeMap.Can Am I doing this?

+3
source share
3 answers

If you need ConcurrentMap collation, see ConcurrentSkipListMap . Given its complexity, it does not block or accelerate. To be more specific:

This class implements a parallel version of SkipLists providing the expected average log (n) time value for containsKey, get, set and delete operations and their variants.

+6
source

A ConcurrentHashMapis still a Map. Thus, you can create a new one TreeMapas follows:

ConcurrentHashMap myMap;
...
TreeMap myTreeMap = new TreeMap( myMap );
+5
source

. java SDK .

Tangens, TreeMap API:

ConcurrentHashMAp myMap;
new TreeMap(myMap);

Please note that this implementation is not synchronized . If several threads access the card at the same time, and at least one of the threads changes the Card structurally, it must be synchronized from the outside”

SortedMap m = Collections.synchronizedSortedMap(new TreeMap(...));
+2
source

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


All Articles