Tagged Questions
0
votes
1answer
66 views
Why is HashEntry in ConcurrentHashMap final?
I am going through source code of ConcurrentHashMap in jdk 7 and have few doubts.
I have already gone through all the questions on CHM on StackOverFlow, but could not find the answer.
Is get ...
3
votes
5answers
160 views
What is the purpose of WeakHashMap when there is HashMap and Concurrent HashMap?
What is the need arises for introducing Weak HashMap when there is already other implementations available.
In short i have two issues :
Why jdk has WeakHashMap when there is HashMap and ...
1
vote
1answer
97 views
Is a ConcurrentHashSet required if threads are using different keys?
Suppose I have a hash set of request IDs that I've sent from a client to a server. The server's response returns the request ID that I sent, which I can then remove from the hash set. This will be ...
3
votes
2answers
113 views
Least value concurrent map
I require an implementation of a map,
that supports concurrency, and only stores the least/most value added (depending on the comparator).
Would the following code work?
class ...
1
vote
2answers
563 views
Need simple explanation how “lock striping” works with ConcurrentHashMap
According to Java Concurrency in Practice, chapter 11.4.3 says:
Lock splitting can sometimes be extended to partition
locking on a variablesized set of independent objects, in which case
it is ...
0
votes
2answers
130 views
Modifying values in ConcurrentHashMap
In ConcurrentHashMap there is concept of segmentation. What it means if two threads are trying to access ConcurrentHashMap they it gets divided in two blocks and default size of blocks is 16.
Now ...
1
vote
1answer
66 views
ConcurrentHashMap Locks increase
As entries increase in the ConcurrentHashMap, rehashing will be done and new hash buckets will be formed (16 to 32).
Q: Will the locks(initially 16) will also increase(to 32) or 16 locks will look on ...
5
votes
1answer
364 views
How does ConcurrentHashMap handle rehashing?
I am wondering how does ConcurrentHashMap handle rehashing while another thread is still writing on another segment/partition. As far as I understand that ConcurrentHashMap locks the segment ...
0
votes
1answer
186 views
How to use generics with a heterogeneous map?
I have a utility method to help use ConcurrentMap.putIfAbsent like this:
public static <K, V> V putIfAbsent(
ConcurrentMap<K, V> map, K key, Callable<V> task) {
try {
...
1
vote
2answers
411 views
ConcurrentHashMap.put V.S. ConcurrentHashMap.replace
From the Javadoc I know ConcurrentHashMap.replace is atomic, but what about ConcurrentHashMap.put? I see they are differently implemented in the source code but I'm not able to figure out their ...
1
vote
4answers
490 views
Concurrent hashmap size() method complexity
I'm wondering if the size() method invoked on ConcurrentHashMap is of the same complexity as the size() method for usual HashMap.
1
vote
1answer
88 views
Why the “next” field in ConcurrentHashMap$HashEntry is final
I'm reading reading the source code of java.util.ConcurrentHashMap and find that the next field in ConcurrentHashMap$HashEntry is final. There are two operations that is possible to modify the value ...
5
votes
4answers
3k views
Are there any drawbacks with ConcurrentHashMap?
I need a HashMap that is accessible from multiple threads.
There are two simple options, using a normal HashMap and synchronizing on it or using a ConcurrentHashMap.
Since ConcurrentHashMap does not ...