Spring batch is a lightweight, fully spring-oriented batch processing framework that can be applied to a large number of data processing systems at the enterprise level. Spring batch is based on Pojo and the well-known spring framework, making it easier for developers to access and leverage enterprise-class services. Spring batch can provide a large number of repeatable data processing functions, including logging/tracking, transaction management, job processing statistics restart, skip, and resource management and other important functions.
Business scenarios: Batches are submitted on a regular basis. Parallel batch processing: Parallel processing work. Enterprise Message-driven processing large-scale parallel processing manual or scheduled restart local processing: skipping records (e.g., rollback)
Technical goal: Leverage the Spring programming model: Enable programmers to focus on business processes and let the spring framework manage processes. Explicitly separate the execution environment and applications for batch processing. Provide the core, common interface. Provides a simple default core execution interface for out-of-the-box (out of the box). Provides configuration, customization, and extension services in the Spring framework. All existing core services can be easily replaced and extended without affecting the underlying layer. Provides a simple deployment model that leverages MAVEN to build separate jar files.
Structure of Spring Batch:
This hierarchical structure has three important components: the application layer, the core layer, the infrastructure layer. The application layer contains all the batch jobs, and the spring framework manages the programmer's custom code. The core layer contains the core classes required for batch launch and control, such as Joblauncher, job, and step. The application layer and core layer are built on top of the infrastructure layer, and the infrastructure layer provides common read (Itemreader), write (Itemwriter), and service (such as Retrytemplate: Retry module. Can be used by the application layer and the core layer).
A brief introduction to the Spring Batch framework process
Introduction to the Spring batch process:
The diagram above depicts the execution of spring batch. The description is as follows:
Each batch will contain a job. Job is like a container, this container has a number of step,batch in the actual work of these step, as for step what to do, no outside reading data, processing data, and then store the data (Itemreader used to read the data, Itemprocessor is used to process data, itemwriter to write data). Joblauncher used to start job,jobrepository is a persistence mechanism provided by the above processing, which provides CRUD operations for Joblauncher,job, and step instances.
External controller call Joblauncher start a job,job call its own step to implement the operation of the data, the step processing is completed, and then the processing results step-by-step back to the previous layer, which is the batch processing implementation of a simple process.
Step execution Process:
When data is fetched from a db or file, the read () operation reads only one record at a time, then passes the read data to the processor (item) processing, and the framework repeats the two steps until the number of records is read to the batch configuration information " Commin-interval "When the value is set, a write operation is called. The processing of the graph is then repeated until all the data has been processed. When the step is finished, either jump to another step, or end the process.
This is the basic workflow of a springbatch.
Through the example of "Hello world", we will discuss the concrete application and implementation of Springbatch.
The engineering structure is as follows:
The results of the implementation are as follows: