Oracle® Fusion Middleware .NET API Reference for Oracle Coherence
12c (12.2.1.4.0)
E90869-02
Synchronized IDictionary wrapper that uses read/write locks to synchronize access to the underlying dictionary.

Namespace: Tangosol.Util.Collections
Assembly: Coherence (in Coherence.dll) Version: 12.2.1.4014 (12.2.1.4014)

Syntax

C#
[SerializableAttribute]
public class SynchronizedDictionary : IDictionary, 
	ICollection, IEnumerable, ISerializable

Remarks

This class uses read/write locks to ensure that only a single thread can modify the underlying dictionary at any given time, while allowing concurrent reads by multiple threads.

While all individual operations exposed by this class are thread-safe, you may still need to synchronize access to an instance of this class if you need to perform multiple operations atomically.

In order to do that, you can do one of the following:

  • Lock the SyncRoot property. Because the write locks used internally also lock SyncRoot, this will prevent concurrent modification. However, concurrent read operations will still be allowed, which means that other threads will be able to see partial updates. If you need truly atomic multi-operation updates, you should use write locks instead.
  • Use read locks. By acquiring a read lock externally, you can ensure that no modifications take place while you are reading from the dictionary. See AcquireReadLock()()()() for details.
  • Use write locks. By acquiring a write lock, you can achieve complete isolation and fully atomic multi-operation updates, as no other thread will be able to either read from or write to the dictionary until the write lock is released. See AcquireWriteLock()()()() for details.

Note 1: If you attempt to acquire a write lock on a thread that holds a read lock, the read lock will be promoted to a write lock as soon as all read locks held by other threads are released.

Note 2: The enumerator returned by the GetEnumerator()()()() method is not thread-safe. You should either acquire a read lock or lock the SyncRoot explicitly if you need to enumerate dictionary entries in a thread-safe manner.

Note 3: This class has been renamed from SynchronizedHashtable to SynchronizedDictionary in Coherence 3.5, to better reflect the fact that it can be used to wrap any IDictionary implementation.

Inheritance Hierarchy

System..::..Object
  Tangosol.Util.Collections..::..SynchronizedDictionary
    Tangosol.Net.Cache..::..LocalCache

See Also