title: CompletableFuture to execute multiple DB queries asynchronously
body: <p>I want to execute multiple DB queries parallelly and store the results in a map. I am trying to do it like this but the map is not getting populated completely when I am accessing the map.</p>
  
  <p>Am I doing anything wrong?</p>
  
  <pre><code> public Map&lt;MapKeyEnums, Set&lt;String&gt;&gt; doDBCalls(String phoneNumber, long timestamp) {
  
           Map&lt;MapKeyEnums, Set&lt;String&gt;&gt; instrumentsEdgesMap = new EnumMap&lt;&gt;(MapKeyEnums.class);
  
           CompletableFuture.supplyAsync(() -&gt; dbReadService.getCall(phoneNumber, PhoneNumber.class, "ABC", timestamp)).
                      thenApply(x -&gt; instrumentsEdgesMap.put(MapKeyEnums.ABC, x));
  
           CompletableFuture.supplyAsync(() -&gt; dbReadService.getCall(phoneNumber, PhoneNumber.class, "XYZ", timestamp)).
                      thenApply(x -&gt; instrumentsEdgesMap.put(MapKeyEnums.XYZ, x));
  
           CompletableFuture.supplyAsync(() -&gt; dbReadService.getCall(phoneNumber, PhoneNumber.class, "DEF", timestamp)).
                      thenApply(x -&gt; instrumentsEdgesMap.put(MapKeyEnums.DEF, x));
  
           return instrumentsEdgesMap;
  
  }
  </code></pre>
  
  <p>Any help will be much appreciated, thanks in advance.</p>