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
-2
votes
2 answers

Can the `ConcurrentHashMap::get` method return a "dirty" valuekkkjjjjj?

While writing the value via put method if another thread tries to read the value for the same key, what will the reader thread get? The old value, the new value or some "junk" value?
-2
votes
1 answer

ConcurrentHashMap and AtomicInteger example in Java

I am trying to implement the following feature: each key in str array should be associated with an Integer which starts from 0 and will be stored in map. after execution the map should contains all keys in str and the count should be consistent with…
-2
votes
2 answers

is it safe to store threads in a ConcurrentMap?

I am building a backend service whereby a REST call to my service creates a new thread. The thread waits for another REST call if it does not receive anything by say 5 minutes the thread will die. To keep track of all the threads I have a collection…
Claudiga
  • 427
  • 1
  • 4
  • 15
-2
votes
2 answers

ConcurrentHashMap read, write and clear()

Suppose there are 3 reading threads and 1 writing thread. The writing thread calls map.clear(). What exception or effect will be caused by it?
Pradeep
  • 12,309
  • 3
  • 20
  • 25
-2
votes
1 answer

how to safely store hashmap in httpsession in java

If I store a concurrent hashmap in a httpsession then how can I use this hashmap in a threadsafe manner? by using the hashmap I mean adding and retrieving from the hashmap in a threadsafe manner. what object should I lock on while getitng/putting in…
-2
votes
3 answers

Thread Safe get method in ConcurrentHashMap

I understand that Concurrent HashMap allows only a single thread at a time to update/write operation for "each segment". However multiple threads are allowed to read values from the map at the same time. For my project, I want to extend this…
-2
votes
2 answers

Fail safe iterator - removal during iteration

If fail safe iterator creates a clone of underlying data structure, why 'D' is never printed in program below? Map acMap = new ConcurrentHashMap(); acMap.put("A", "Aye"); acMap.put("B", "Bee"); acMap.put("C",…
Azodious
  • 13,752
  • 1
  • 36
  • 71
-2
votes
1 answer

Concurrent hash map Java's internal mechanism

As we all know concurrent hash map allows multiple threads to read/write simultaneously using segment locks. My question is: How Java internally manages the map when a thread t1 is writing on a bucket and thread t2 is reading on the same bucket and…
Imran S
  • 157
  • 2
  • 10
-2
votes
1 answer

How to get a specific key or value from a ConcurrentHashMap

I honestly tried to look at a lot of posts but I am not sure what is the correct way of getting a specific key from a ConcurrentHashMap. How to get the first key in a ConcurrentHashMap? How to get the key on first encounter of a certain value? How…
user1464629
  • 57
  • 1
  • 9
-2
votes
1 answer

ConcurrentHashMap memory allocation

ConcurrentHashMap chm= new ConcurrentHashMap(8,1,16); Now according to the above configuration the ConcurrentHashMap will divide the table into 16 segments. Now each segment is a individual hasmap. Let's take the entry object size as x bytes. Then…
Maclean Pinto
  • 1,075
  • 2
  • 17
  • 39
-2
votes
3 answers

Concurrent Modification Exception for hashmap

Map> regions = Service.getWhseByRegions(); for(String region:regions.keySet()){ warehouseList=getAuthorizedWarehouse(dashboardWarhs,regions.get(region)); if(warehouseList!=null && warehouseList.size()>0){ …
pnaga
  • 21
  • 1
  • 5
-2
votes
1 answer

std::unordered_map not compiling with icc

Like the title says, unordered_map isn't compiling for me. I get an error saying "error: namespace "std" has no member "unordered_map"" I'm compiling with this command icc test.cpp -std=c++0x This is the program I'm trying to compile: #include…
-3
votes
2 answers

concurrentHashMap.merge(key,1,Integer::sum) : Is this operation threadsafe?

concurrentHashMap.merge(key,1,Integer::sum) Is the above operation thread-safe? What is the best way to make it threadsafe?
-3
votes
1 answer

Java map cache for highly multiple threads

Please suggest which map can be used for caching. My use case is a highly multi threaded server that I would like to synchronise put map but get map is not synchronised. My expectation is: if put happens, then an immediate get should have the…
erdarun
  • 441
  • 1
  • 8
  • 14
-3
votes
1 answer

Interleaving two threads such that one of the thread gets null when called putIfAbsent of concurrentHashMap

can someone explain the interleaving of two threads such that one of the thread gets null when two threads call putIfAbsent of ConcurrentHashMap in Java?
user1870400
  • 6,028
  • 13
  • 54
  • 115
1 2 3
54
55