SHARE
TWEET

Untitled

a guest Jun 19th, 2019 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class MyClass{
  2.  
  3.     private final Map<(MyObj, Map<String, List<String>>> conMap = new ConcurrentHashMap<>();
  4.  
  5.     //...
  6.  
  7.     //adding new record into conMap:
  8.     private void addToMap(MyObj id, String name, String value){
  9.         conMap.putIfAbsent(id, new ConcurrentHashMap<>());
  10.         Map<String, List<String>> subMap = conMap.get(id);
  11.         synchronized(subMap){                            // <-- is it necessary?
  12.             subMap.putIfAbsent(name, new ArrayList<>());
  13.             subMap.get(name).add(value);
  14.         }
  15.     }
  16.  
  17.     //...
  18.  
  19.     public void doSomthing((MyObj id){
  20.         List<Map<String, List<String>>> mapsList = new LinkedList<>();
  21.         for(MyObj objId: conMap.keySet()){              // <-- seems unnecessary..
  22.             if(objId.equals(id)){
  23.                 mapsList.add(conMap.get(objId));
  24.             }
  25.         }
  26.  
  27.         for(Map<String, List<String>> map: mapsList){
  28.             synchronized(map){                       // <-- is it necessary?
  29.                 //do some stuff..
  30.             }
  31.     }
  32.  
  33.     //...
  34.  
  35. }
  36.      
  37. if(conMap.containsKey(id)){
  38.     mapsLists.add(conMaps.get(id));
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top