title: How can I wait for completion of an Elastic MapReduce job flow in a Java application?
body: <p>Recently I've been working with Amazon Web Services (AWS) and I've noticed there is not much documentation on the subject, so I added my solution.</p>
  
  <p>I was writing an application using Amazon Elastic MapReduce (Amazon EMR). After the calculations ended I needed to perform some work on the files created by them, so I needed to know when the job flow completed its work.</p>
  
  <p>This is how you can check if your job flow completed:</p>
  
  <pre><code>AmazonElasticMapReduce mapReduce = new AmazonElasticMapReduceClient(credentials);
  
  DescribeJobFlowsRequest jobAttributes = new DescribeJobFlowsRequest()
      .withJobFlowStates("COMPLETED");
  
  List&lt;JobFlowDetail&gt; jobs = mapReduce.describeJobFlows(jobAttributes).getJobFlows();
  JobFlowDetail detail = jobs.get(0);
  
  detail.getJobFlowId(); //the id of one of the completed jobs
  </code></pre>
  
  <p>You can also look for a specific job id in <code>DescribeJobFlowsRequest</code> and then to check if that job has finished of failed.</p>
  
  <p>I hope it will help others.</p>