title: Waiting for an asynchronous call to complete first and then proceed in Java
body: <p>I have a situation wherein I call a method which in turn triggers a asynchronous HTTP REST call(sends the status later to another endpoint) before it proceeds further. I want the method to wait until i get the response back to the endpoint, check the status i got and proceed further. I am looking for a feasible solution in Java. Any pseudo code or implementation will be helpful</p>
  
  <p>saw similar case @ <a href="https://stackoverflow.com/questions/4937609/lightweight-way-of-waiting-for-a-group-of-asynchronous-java-calls">Lightweight way of waiting for a group of asynchronous Java calls</a> but not much idea about the same whether it is easy to implement.</p>
  
  <p><strong>Implementation details</strong></p>
  
  <p>I have JAX-RS endpoint to handle the async response as below</p>
  
  <pre><code>@POST
  @Path("/status")
  @Consumes("application/xml")
  public Response processConfigStatus(@Context UriInfo uriInfo, ConfigStatus configStatus)
  {
     // process Status got from the async REST call
     return ResponseHelper.createNoContentResponse();
  }
  </code></pre>
  
  <p><strong>Class which handles and processes</strong></p>
  
  <pre><code>Class ProcessData{
  
    public void updateData()
      checktStatus(uri);
      update();// should wait untill the processConfigStatus() endpoint gives status
    }
  
    private  checktStatus(String uri){
       // makes a REST call to a URI using a JAX-RS webclient or a httpclient this returns HTTP 200 or 204 code immediatley. And then the Server process the request asynchronously and gives back the status to JAX-RS endpoint(/status).
       post(uri);
    }
  
  }
  </code></pre>
  
  <p><strong>Method call from another Class</strong></p>
  
  <pre><code>ProcessData pd = new ProcessData()
  pd.updateData();
  </code></pre>