Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent of java's ConcurrentHashMap in C#? [duplicate]

Tags:

c#

is there anything?

like image 233
CSharpDevLondon Avatar asked Jan 07 '09 15:01

CSharpDevLondon


People also ask

What is faster Hashtable or ConcurrentHashMap?

ConcurrentHashMap uses multiple buckets to store data. This avoids read locks and greatly improves performance over a HashTable .

Can we replace Hashtable with ConcurrentHashMap?

Is it safe to replace the Hashtable instances with ConcurrentHashmap instances for performance gain? In most cases it should be safe and yield better performance. The effort on changing depends on whether you used the Map interface or Hashtable directly.

What is difference between synchronizedMap and ConcurrentHashMap?

synchronizedMap() requires each thread to acquire a lock on the entire object for both read/write operations. By comparison, the ConcurrentHashMap allows threads to acquire locks on separate segments of the collection, and make modifications at the same time.

What is default size of ConcurrentHashMap?

Creates a new, empty map with a default initial capacity (16), load factor (0.75) and concurrencyLevel (16).


1 Answers

There is a generic Dictionary class for implementing associative arrays (aka hashtables). Recently MS came out with the ConcurrentDictionary class: http://msdn.microsoft.com/en-us/library/dd287191.aspx which is probably what you want. It's .Net 4+ though. :(

like image 167
Darwyn Avatar answered Oct 08 '22 03:10

Darwyn