title: Spring-batch exiting with Exit Status : COMPLETED before actual job is finished?
body: <p>In my Spring Batch application I have written a CustomItemWriter which internally writes item to DynamoDB using DynamoDBAsyncClient, this client returns Future object. I have a input file with millions of record. Since CustomItemWriter returns future object immediately my batch job exiting within 5 sec with status as COMPLETED, but in actual it is taking 3-4 minutes to write all item to the DB, I want that batch job finishes only after all item written to DataBase. How can i do that?</p>
  
  <p>job is defined as below</p>
  
  <pre><code>    &lt;bean id="report" class="com.solution.model.Report" scope="prototype" /&gt;
          &lt;batch:job id="job" restartable="true"&gt;
              &lt;batch:step id="step1"&gt;
                  &lt;batch:tasklet&gt;
                      &lt;batch:chunk reader="cvsFileItemReader"  processor="filterReportProcessor" writer="customItemWriter"
                          commit-interval="20"&gt;
                      &lt;/batch:chunk&gt;
                  &lt;/batch:tasklet&gt;
              &lt;/batch:step&gt;
          &lt;/batch:job&gt;
  &lt;bean id="customItemWriter" class="com.solution.writer.CustomeWriter"&gt;&lt;/bean&gt;
  </code></pre>
  
  <p>CustomeItemWriter is defined as below</p>
  
  <pre><code>public class CustomeWriter implements ItemWriter&lt;Report&gt;{
      public void write(List&lt;? extends Report&gt; item) throws Exception {
      List&lt;Future&lt;PutItemResult&gt;&gt; list = new LinkedList();
      AmazonDynamoDBAsyncClient client = new AmazonDynamoDBAsyncClient();
          for(Report report : item) {
              PutItemRequest req = new PutItemRequest();
              req.setTableName("MyTable");
              req.setReturnValue(ReturnValue.ALL_ODD);
              req.addItemEntry("customerId",new 
              AttributeValue(item.getCustomeId()));
              Future&lt;PutItemResult&gt; res = client.putItemAsync(req);
              list.add(res);
              }
      }
  
  }
  </code></pre>
  
  <p>Main class contains</p>
  
  <pre><code>JobExecution execution = jobLauncher.run(job, new JobParameters());
  System.out.println("Exit Status : " + execution.getStatus());
  </code></pre>
  
  <p>Since in ItemWriter its returning future object it doesn't waits to complete the opration. And from the main since all item is submitted for writing Batch Status is showing COMPLETED and job terminates.
  I want that this job should terminate only after actual write is performed in the DynamoDB.
  Can we have some other step well to wait on this or some Listener is available? </p>