The spring batch job has a lot of metadata at run time, which is typically stored in memory or in the database, because spring batch is configured to use HSQLDB in the default configuration, which means that all of the metadata is stored in memory during job operation. The end of the job will automatically disappear as the process ends, where we recommend configuring Jobrepository to use MySQL.
In this case, Spring batch uses the database to maintain state in a single execution or from one execution to another, and the job execution information includes the job instance, the parameters passed in, the results of the execution, and the results of each step execution are stored in the database The database uses 6 tables to store related information:
batch_job_instance
As we all know, a job instance is created when the job is run, the job instance contains the job instance itself and the job parameters, and all the job instance itself information will be saved in the Batch_job_instance table:
Field |
Describe |
job_instance_id |
Primary key of the table |
VERSION |
Version of the record |
Job_name |
Job name to be executed |
Job_key |
The hash value of the job name and job parameter, which is used to uniquely indicate a job instance |
Batch_job_params
This table contains all the parameters that are passed to the job, as mentioned above, and the parameters are used by spring batch as part of the job label. This table contains the following fields:
Field |
Describe |
job_instance_id |
A foreign key that represents batch_job_instance |
Type_cd |
The type that represents the stored value (string, date, long, double) |
Key_name |
The key for the job parameter (the job parameter is passed as a key-value pair) |
String_val |
When this parameter is a string type, the value |
Date_val |
Date type parameter values |
Long_val |
Long Integer parameter values |
Double_val |
Double or single-precision parameter values |
batch_job_executionand thebatch_step_execution
When a job is created and executed, the running state of the job is saved in the Batch_job_execution table, which includes: Start time, end time, the result of the most recent execution;
The Batch_step_execution table is similar to Batch_job_execution, which contains the parameters of the start time, the end time, the number of commits and the step status of each step in the execution process.
batch_job_execution field information for the table:
Field |
Describe |
job_execution_id |
Primary key of the table |
VERSION |
Version of the record |
job_instance_id |
Foreign keys to the Batch_job_instance table |
Create_time |
The time that the job instance was created |
Start_time |
Time the job started executing |
End_time |
The time at which the job execution ended, whether successful or not |
STATUS |
Status of the job being executed |
Exit_code |
Exit code on Job return |
Exit_message |
Launch message on Job return |
last_updated |
The time the current record was last updated |
batch_step_execution field information for the table:
step_execution_id |
Primary key of the table |
VERSION |
Version of the record |
Step_name |
The name of step that is configured in the job XML |
job_execution_id |
Foreign keys connected to the Batch_job_execution table |
Start_time |
Time of Step start |
End_time |
Step completion time, whether successful or not |
STATUS |
Current status of step |
Commit_count |
Number of times the current step was commit |
Read_count |
Number of times the current step reads the database |
Filter_count |
The number of item currently read by step |
Write_count |
The number of item currently written by step |
Read_skip_count |
Number skipped when reading item |
Write_skip_count |
Number of skipped when writing item |
Process_skip_count |
Number of item not itemprocessor processed after Itemreader read |
Rollback_count |
The total number of rollback during step execution |
Exit_code |
Exit code returned when step is completed |
Exit_message |
Exit message returned when step completes |
last_updated |
The time the record was last updated |
Batch_job_execution_contextand theBatch_step_execution_context
This is a two context-related table that is used to store the persisted version of the job or step-related executioncontext, and the ExecutionContext in Spring batch is similar to a servlet in a Web application The context or session, which provides a global space for storing information, is essentially a key-value pair of scopes in a job or step; the job or step's executioncontext is used to pass information in a specific scope, if the job , it is used to pass information between step and step, which, if it is step, is used to pass information during the processing of multiple records.
table Batch_job_execution_context and Batch_step_execution_context are serialized versions of these key-value pairs, which are almost identical except for a foreign key;
Fields |
description |
|
reference from table batch_job_execution or batch_step_execution foreign key |
short_context |
|
serialized_context | TD style= "border:1px solid silver; Border-collapse:collapse; Padding:3px "> a serialized ExecutionContext to use
when retrying in the future.
Spring Batch Learning (iii) Jobrepository