728x90

Historically, offline processing (such as batch jobs) has been launched from the command-line, as described earlier. However, there are many cases where launching from an HttpRequest is a better option. Many such use cases include reporting, ad-hoc job running, and web application support. Because a batch job (by definition) is long running, the most important concern is to launch the job asynchronously:

 

Figure 1. Asynchronous Job Launcher Sequence From Web Container

 

 

The controller in this case is a Spring MVC controller. See the Spring Framework Reference Guide for more about Spring MVC. The controller launches a Job by using a JobLauncher that has been configured to launch asynchronously, which immediately returns a JobExecution. The Job is likely still running. However, this nonblocking behavior lets the controller return immediately, which is required when handling an HttpRequest. The following listing shows an example:

@Controller
public class JobLauncherController {

    @Autowired
    JobLauncher jobLauncher;

    @Autowired
    Job job;

    @RequestMapping("/jobLauncher.html")
    public void handle() throws Exception{
        jobLauncher.run(job, new JobParameters());
    }
}
Copied!

 

'Java > Spring Boot JPA' 카테고리의 다른 글

not importing JSONException and JSONObject issue  (0) 2024.04.04
JobParametersIncrementer  (0) 2024.04.03
Builder and AllArgsConstructor Annotation  (31) 2024.04.02
Item Processing in Spring Batch  (0) 2024.04.01
ItemReaders and ItemWriters  (31) 2024.03.27

+ Recent posts