title: Spring integration Configuration to wait for outcome of async batch job
body: <p>I use Spring Batch admin project in which I have got a job which processes files from a particular folder asynchronously. Currently I run it via batch admin ui by passing the relevant job parameters. </p>
  
  <p>Now, I am trying to automate this process by using file inbound channel adapter. I have configured the service activator which would invoke the batch job whenever it receives a file. I have a new requirement now to invoke another batch job once the the first file upload job is complete . To do this, I have created another service activator that uses the output channel of the first service activator. But since the batch job runs asynchronously, then next batch job is getting executed immediately. Is there a way for the second batch job to wait till the first batch job completes.</p>
  
  <p>My current configuation is</p>
  
  <pre><code> &lt;file:inbound-channel-adapter id="filesIn" directory="file:${input.directory}" filename-pattern="*.csv" prevent-duplicates="true"&gt;
      &lt;integration:poller id="poller" fixed-delay="10000"/&gt;
  &lt;/file:inbound-channel-adapter&gt;
  &lt;integration:channel id="statusChannel"/&gt;
  
  &lt;integration:service-activator input-channel="filesIn" output-channel="statusChannel"
                                 ref="handler" method="process"/&gt;
  
  &lt;bean id="handler" class="AnalysisMessageProcessor"&gt; 
      &lt;property name="job" ref="A-importGlobalSettingsDataJob"/&gt; &lt;!--1st job --&gt;
      &lt;property name="requestHandler" ref="jobMessageHandler"/&gt;
  &lt;/bean&gt;       
  
  &lt;bean id="jobMessageHandler" class="org.springframework.batch.integration.launch.JobLaunchingMessageHandler"&gt;
      &lt;constructor-arg ref="jobLauncher" /&gt; &lt;!--spring batch admins async job launcher --&gt;
  &lt;/bean&gt;                         
  
  &lt;integration:service-activator input-channel="statusChannel" ref="jobHandler" method="process"/&gt;   
  &lt;bean id="jobHandler" class="JobHandler"&gt; &lt;!--This Job handler should get invoked only after the 1st batch job is completed. Currently I am just printing the exit status code of 1st job--&gt;
  </code></pre>
  
  <p>Any help would be very much appreciated.</p>