ConcurrentMapK,V


ConcurrentMap<K,V> java.util.concurrent

Java 5.0 collection

This interface extends the java.util.Map interface to add four important atomic methods . As with the Map interface, the type variables K and V represent the types of the mapped keys and values.

putIfAbsent( ) atomically tests whether a key is already defined in the map, and if not, maps it to the specified value. remove( ) atomically removes the specified key from the map, but only if it is mapped to the specified value. It returns true if it modified the map. There are two versions of the atomic replace( ) method. The first checks whether the specified value is already mapped to a value. If so, it replaces the existing mapping with the specified value and returns true . Otherwise , it returns false . The three-argument version of replace( ) maps the specified key to the specified new value, but only if the key is currently mapped to the specified old value. It returns true if the replacement was made and false otherwise.

Figure 16-77. java.util.concurrent.ConcurrentMap<K,V>

 public interface  ConcurrentMap<K,V>  extends java.util.Map<K,V> {  // Public Instance Methods  V  putIfAbsent  (K  key  , V  value  );        boolean  remove  (Object  key  , Object  value  );        V  replace  (K  key  , V  value  );        boolean  replace  (K  key  , V  oldValue  , V  newValue  );   } 

Implementations

ConcurrentHashMap



Java In A Nutshell
Java In A Nutshell, 5th Edition
ISBN: 0596007736
EAN: 2147483647
Year: 2004
Pages: 1220

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net