Spring Batch: starting a job from within a Spring MVC contorller WITH A NEW THREAD

前端 未结 3 1031
夕颜
夕颜 2021-01-01 03:45

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:

3条回答
  •  不思量自难忘°
    2021-01-01 04:38

    The official documentation describes your exact problem and a solution in 4.5.2. Running Jobs from within a Web Container:

    [...] The controller launches a Job using a JobLauncher that has been configured to launch asynchronously, which immediately returns a JobExecution. The Job will likely still be running, however, this nonblocking behaviour allows the controller to return immediately, which is required when handling an HttpRequest.

    Spring Batch http://static.springsource.org/spring-batch/reference/html-single/images/launch-from-request.png

    So you were pretty close in trying to use TaskExecutor, however it needs to be passed to the JobLauncher instead:

    
        
        
    
    

    Disclaimer: I have never used Spring Batch...

提交回复
热议问题