title: Spring Batch: starting a job from within a Spring MVC contorller WITH A NEW THREAD
body: <p>I have a Spring-Batch job that I launch from a Spring MVC controller. The controller gets an uploaded file from the user and the job is supposed to process the file:</p>
  
  <pre><code>@RequestMapping(value = "/upload")
  public ModelAndView uploadInventory(UploadFile uploadFile, BindingResult bindingResult) {
  
      // code for saving the uploaded file to disk goes here...
  
      // now I want to launch the job of reading the file line by line and saving it to the database,
      // but I want to launch this job in a new thread, not in the HTTP request thread,
      // since I so not want the user to wait until the job ends.
      jobLauncher.run(
                      jobRegistry.getJob(JOB_NAME),
                      new JobParametersBuilder().addString("targetDirectory", folderPath).addString("targetFile", fileName).toJobParameters()
                      );
  
      return mav;
  }
  </code></pre>
  
  <p>I've tried the following XML config:</p>
  
  <pre><code>&lt;job id="writeProductsJob" xmlns="http://www.springframework.org/schema/batch"&gt;
      &lt;step id="readWrite"&gt;
          &lt;tasklet task-executor="taskExecutor"&gt;
              &lt;chunk reader="productItemReader" writer="productItemWriter" commit-interval="10" /&gt;
          &lt;/tasklet&gt;
      &lt;/step&gt;
  &lt;/job&gt;
  
  &lt;bean id="taskExecutor"
      class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor"&gt;
      &lt;property name="corePoolSize" value="5" /&gt;
      &lt;property name="maxPoolSize" value="5" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>...but it seems like the multithreading happens only within the job boundaries itself. I.e., the controller thread waits until the job ends, and the job execution is handled by multiple threads (which is good but not the main thing I wanted). The main thing I wanted is that the job will be launched on a separate thread (or threads) while the controller thread will continue its execution without waiting for the job threads to end.</p>
  
  <p>Is there a way to achieve this with Spring-batch?</p>