Wednesday 17 September 2014

ConcurrentMap

ConcurrentMap extends Map interface. ConcurrentMap offers better concurrency as compared to HashTable. ConcurrentHashMap doesn't lock entire map while you are trying to perform read and write operations.

import java.util.concurrent.*;

public class ConcurrentMapEx {
    public static void main(String args[]){
        ConcurrentMap<Integer, String> map;
        map = new ConcurrentHashMap<> ();
        
        map.put(1, "Arjun");
        map.put(2, "Krishna");
        map.put(3, "Anand");
        map.put(4, "Aswini");
        
        System.out.println(map);
    }
}

Output
{1=Arjun, 2=Krishna, 3=Anand, 4=Aswini}



Prevoius                                                 Next                                                 Home

No comments:

Post a Comment