Questions tagged [concurrenthashmap]

The Java ConcurrentHashMap data structure. The ConcurrentHashmap is a hash table supporting full concurrency of retrievals and adjustable expected concurrency for updates. It allows concurrent modification of the Map from several threads without the need to block them

The Java ConcurrentHashMap data structure.

This class provides a thread-safe variant of HashMap.

811 questions
10
votes
1 answer

Double checked locking with regular HashMap

Back to concurrency. By now it is clear that for the double checked locking to work the variable needs to be declared as volatile. But then what if double checked locking is used as below. class Test { private final Map map = new…
10
votes
3 answers

Java Remove Specific Item From ConcurrentHashMap

Is using the remove() method okay? I've read an article that synchronization hasn't been added to the remove method. How do I properly remove a specific item from a ConcurrentHashMap? Example Code: ConcurrentHashMap storage =…
user4350786
10
votes
2 answers

ConcurrentHashMap parallelismThreshold

The ConcurrentHashMap got a couple new methods. I have two questions regarding them: Why aren't they declared in ConcurrentMap? What exactly does the parallelismThreshold mean or do?
10
votes
3 answers

How to resolve the findbug Sequence of calls to java.util.concurrent.ConcurrentHashMap may not be atomic

Hi I am getting the bug "Sequence of calls to java.util.concurrent.ConcurrentHashMap may not be atomic " when i am running find bug in my project for the below code. public static final ConcurrentHashMap> personTypeMap = new…
Murali
  • 341
  • 2
  • 7
  • 24
10
votes
2 answers

Disadvantage of increasing number of partition in Java ConcurrentHashMap?

Java ConcurrentHashMap maintains partitions internally. Each partition can have locking separately. There can be scenarios where all the keys accessed by multiple thread fall into the same partition and partitions may not be helpful. Increasing the…
saurabh
  • 101
  • 3
10
votes
3 answers

ConcurrentHashMap vs ReentrantReadWriteLock based Custom Map for Reloading

Java Gurus, Currently we have a HashMap which is being read frequently and modified occasionally and we are having issues that during the modification/reloading, Read operation returns null which is not acceptable. To…
Bharat Sinha
  • 13,973
  • 6
  • 39
  • 63
9
votes
1 answer

TBB Concurrent Hash map

I am implementing tbb's concurrent hash map to compare the performance of it against a suite of other concurrent hash tables. However the performance I get out of it is horrendous, I just can't believe it is that slow compared to other concurrent…
Steven Feldman
  • 833
  • 1
  • 15
  • 28
9
votes
2 answers

What is the difference between Collectors.toConcurrentMap and converting a Map to ConcurrentHashMap via Collectors.toMap supplier option?

I want to convert a Map into a ConcurrentHashMap via Java 8 Stream and Collector interface, and there are two options I can use. The first: Map mb = persons.stream() .collect(Collectors.toMap( …
KayV
  • 12,987
  • 11
  • 98
  • 148
9
votes
2 answers

Java: How to take static snapshot of ConcurrentHashMap?

Java doc says that return values of method values() and entrySet() are backed by the map. So changes to the map are reflected in the set and vice versa. I don't want this to happen to my static copy. Essentially, I want lots of concurrent operations…
PHcoDer
  • 1,166
  • 10
  • 23
9
votes
3 answers

Potential use for SoftReference with value (equals) equality

I previously come to the conclusion that if you need a SoftReference with value (equals) based equality then one had a bad design, excepting an interner from this. This is following Google Collections and Guava not including such a class. But I've…
Blair Zajac
  • 4,555
  • 3
  • 25
  • 36
9
votes
6 answers

ThreadLocal HashMap vs ConcurrentHashMap for thread-safe unbound caches

I'm creating a memoization cache with the following characteristics: a cache miss will result in computing and storing an entry this computation is very expensive this computation is idempotent unbounded (entries never removed) since: the inputs…
Maian
  • 528
  • 2
  • 5
  • 11
9
votes
3 answers

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 differences. Any gurus to give some guidelines about…
9
votes
5 answers

concurrent HashMap: checking size

Concurrent Hashmap could solve synchronization issue which is seen in hashmap. So adding and removing would be fast if we are using synchronize key work with hashmap. What about checking hashmap size, if mulitple threads checking concurrentHashMap…
user84592
  • 4,750
  • 11
  • 55
  • 91
8
votes
2 answers

ConcurrentHashMap computeIfAbsent tell if first time or not

It's complicated for me to articulate a proper title for this. But an example should make it far simpler. Suppose I have this: final class Cache { private static final ConcurrentHashMap> CACHE = ... static List
Eugene
  • 117,005
  • 15
  • 201
  • 306
8
votes
2 answers

Bug: parameter 'initialCapacity' of ConcurrentHashMap's construct method?

one of the construct method of java.util.concurrent.ConcurrentHashMap: public ConcurrentHashMap(int initialCapacity) { if (initialCapacity < 0) throw new IllegalArgumentException(); int cap = ((initialCapacity >=…
Anonemous
  • 307
  • 2
  • 8