From the course: Spring: Spring Batch
Spring Batch architecture
From the course: Spring: Spring Batch
Spring Batch architecture
- When we start to impact Spring Batch's Architecture we find two prominent concepts. Jobs and steps. A job represents the entire batch process that we want to execute. It defines one or more steps that execute in an order we commonly call a flow. A step is a phase in a batch job that defines how the actual processing will occur for that portion of the job. The processing logic within a step may read data from a data source, process it and then write it to another data source. A job can contain multiple steps and the flow from one step to another can be dynamic. Meaning it can be conditional or occur in parallel. The entire job is launched using a Job Launcher, which may pass JobParameters to the job. As the job runs, metadata regarding the job is written to the job repository. When running Spring Batch jobs the concept of a job instance and a job execution must be understood. When a job launcher creates a job it typically will pass the name of the job and some parameters. The combination of the Job Name and its parameters defines a new JobInstance which is created. When we execute a JobInstance, we create a new JobExecution. In some situations, such as failures, we might execute a job multiple times with the same parameters. So it is the same JobInstance because it's the same job with the same parameters. But in this case, a different JobExecution is created because it is the second execution of a particular JobInstance. So when we execute a job with the same parameters it is the same instance of a job and for each time that we execute a JobInstance we get a new JobExecution. Here we'll see the same job ran with different parameters, which creates a different JobInstance and a new execution of that JobInstance. So here we see in attempt three, we have the same job name but you'll notice that the JobParameter being passed is different. This means that we're going to have a different JobInstance and when that JobInstance is executed we're going to get a different JobExecution. As the steps execute within a job, there's a very similar concept that is applied. So each execution of a step is going to create a new StepExecution. The StepExecution is associated with a JobExecution and its possible to have multiple StepExecutions when a failure occurs in our processing and we need to restart a job. As they execute, metadata regarding JobInstance, JobExecutions and StepExecutions are all stored in the JobRepository. Here you see some of the tables the JobRepository uses to store this information in a relational database. Of particular interest is the status and exit code columns found within the execution tables. These columns hold information regarding the success or failure of a job. We'll be talking about these in more detail later in the course. The final item I want to discuss is the two types of steps found within Spring Batch. The first type of step is known as a tasklet and we've seen this in our first example. It contains a single method on its interface named execute, that runs over and over until it gives signal to stop. Tasklets are typically used for things like setup logic, stored procedures or other custom logic that cannot be achieved without the box components. The second type of step is known as a chunk-based step. It is used in scenarios where we need to process data from a data source. The chunk-based step leverages the ItemReader interface to read chunks of data from a data store. Then writes the chunks in a transaction using the ItemWriter. Optionally, we can include an ItemProcessor implementation to perform transformations on the data. So those are the high level concepts you will need to know for working with batch jobs in Spring Batch. Lets write some code and check these out with a few examples.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Spring Batch architecture5m 28s
-
(Locked)
Configuring a job repository6m 13s
-
(Locked)
Job parameters6m 59s
-
(Locked)
Building jobs with multiple steps5m 26s
-
(Locked)
Restarting jobs6m 33s
-
(Locked)
Job flow5m 38s
-
(Locked)
Building conditional flows6m 48s
-
(Locked)
Controlling flow with custom statuses6m 59s
-
(Locked)
Challenge: Creating a conditional flow1m 20s
-
(Locked)
Solution: Creating a conditional flow6m 35s
-
-
-
-
-
-
-
-