concurrenthashmap

Does a call to a threadsafe function need to be syncronized too?

If I'm using ConcurrentHashMap (where the put is thread safe) , and I supply a public function myPut that uses the ConcurrentHashMap put - do I need to synchronize my function? meaning : should this be synchronized? ConcurrentHashMap map; public void myPut(int something) { this.map.put(something); } ...

2-D (concurrent) HashMap: 2-property key type? hashmap of hashmaps? [update]

So I need a 2-dimensional ConcurrentHashMap. It has to be as blazing fast as possible, as I'm going to be adding to and updating its values extremely frequently. It's in a multithreaded application, hence the choice to use ConcurrentHashMap instead of just HashMap. Both the "x" and "y" indices are integers with a known range (0 throug...

Why does ConcurrentHashMap prevent null keys and values?

The JavaDoc of ConcurrentHashMap says this: Like Hashtable but unlike HashMap, this class does not allow null to be used as a key or value. My question: why? 2nd question: why doesn't Hashtable allow null? I've used a lot of HashMaps for storing data. But when changing to ConcurrentHashMap I got several times into trouble because...

Synchronization of ConcurrentHashMap modifiers

I would like to cache some IO with the help of ConcurrentHashMap. The modification on the binary file should be reflected in cache as well. Since the cache is going to be used by multiple threads all IO operations are synchronized. Modifications of map go inside the same synchronized block. Which roughly looks like: synchronized (file) ...

ConcurrentHashMap constructor parameters?

I am wondering about the parameters for constructing a ConcurrentHashMap: initialCapacity is 16 by default (understood). loadFactor is 0.75 by default. concurrencyLevel is 16 by default. My questions are: What criteria should be used to adjust loadFactor up or down? How do we establish the number of concurrently updating threads? W...

Strategy in java to clean up / remove unused map elements

Hi, I'm implementing a "manager" in my web app that can be called to set and get which web site context the current thread is in (we white label our site so the web site context represents which site we're on) I'm trying to work out what the best strategy to do this, currently I'm implementing the store of Threads to WebSiteContexts...

ConcurrentHashMap and putAll() method

Normally (ie. not concurrently), putAll() cannot be more efficient than using lot's of calls to put(), even assuming that you exclude the cost of building the other Map that you pass to putAll(). That's because putAll() will need to iterate the passed Map's elements, as well as running through the algorithm for adding each key value pair...

Is ConcurrentHashMap.get() guaranteed to see a previous ConcurrentHashMap.put() by different thread?

Is ConcurrentHashMap.get() guaranteed to see a previous ConcurrentHashMap.put() by different thread? My expectation is that is is, and reading the JavaDocs seems to indicate so, but I am 99% convinced that reality is different. On my production server the below seems to be happening. (I've caught it with logging.) Pseudo code example...

Is it possible to have more than 32 locks in ConcurrentHashMap

I read ConcurrentHashMap works better in multi threading than Hashtable due to having locks at bucket level rather than map wide lock. It is at max 32 locks possible per map. Want to know why 32 and why not more than 32 locks. ...

When should I use ConcurrentSkipListMap?

In Java, ConcurrentHashMap is there for better multithreading solution. Then when should I use ConcurrentSkipListMap? Is it a redundancy? Does multithreading aspects between these two are common? ...

How to implement ConcurrentHashMap with features similar in LinkedHashMap?

I have used LinkedHashMap with accessOrder true along with allowing a maximum of 500 entries at any time as the LRU cache for data. But due to scalability issues I want to move on to some thread-safe alternative. ConcurrentHashMap seems good in that regard, but lacks the features of accessOrder and removeEldestEntry(Map.Entry e) found in...

Implementing a cache using a java ConcurrentHashMap

Hello, I'd like to implement a simple caching of heavyweight objects in a web java application. But I can't figure out how to do it properly. Am I missing something or ConcurrentHashMap methods (putIfAbsent, ...) are not enough and additional synchronization is needed ? Is there a better simple API (In memory storage, no external confi...

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 come across an issue that I think could use such an object. We have an asset management ...

ConcurrentHashMap in Java?

what is the use of concurrent hash map in java? where we have to use this? what are the comforts in it? help please. how it works? sample codes are easy to understandable.. ...

Java Concurrency : Volatile vs final in "cascaded" variables?

Hello Experts, is final Map<Integer,Map<String,Integer>> status = new ConcurrentHashMap<Integer, Map<String,Integer>>(); Map<Integer,Map<String,Integer>> statusInner = new ConcurrentHashMap<Integer, Map<String,Integer>>(); status.put(key,statusInner); the same as volatile Map<Integer,Map<String,Integer>> status = new ConcurrentHash...

Best way to audit concurrenthashmap

I use concurrenthashmap to store my data.And I wanna audit, pass over a part of my map according to a timer.I mean, a timer will tell me to start audit and I will pass over a part of the map and then I will stop auditing until the timer's next poke, when timer pokes me again I will start audit where I stopped last time. But, I'm not sure...

Is it possible for ConcurrentHashMap to "deadlock"?

We have come across a strange issue with ConcurrentHashMap, where two threads appears to be calling put(), and then waiting forever inside the method Unsafe.park(). From the outside, it looks like a deadlock inside ConcurrentHashMap. We have only seen this happen once so far. Can anyone think of anything that could cause these symptoms...

Atomically incrementing counters stored in ConcurrentHashMap

I would like to collect some metrics from various places in a web app. To keep it simple, all these will be counters and therefore the only modifier operation is to increment them by 1. The increments will be concurrent and often. The reads (dumping the stats) is a rare operation. I was thinking to use a ConcurrentHashMap. The issue i...

Sorting the values in a java ConcurrentHashMap

I have the following code for sorting a ConcurrentHashMap: ConcurrentHashMap<String,String> text = new ConcurrentHashMap<String,String>(); .... List<String> list = new ArrayList<String>(text.values()); Collections.sort(list); Which throws a NoSuchElementException: Caused by: java.util.NoSuchElementException at library.ArrayL...

Java ConcurrentHashMap not thread safe.. wth?

Hello I was using HashMap before like public Map<SocketChannel, UserProfile> clients = new HashMap<SocketChannel, UserProfile>(); now I've switched to ConcurrentHashMap to avoid synchronized blocks and now i'm experiencing problems my server is heavily loaded with 200-400 concurrent clients every second which is expected to grow...