Spring Batch (i): Basic section

Source: Internet
Author: User

Spring Batch (i): Basic section Blog Category:
    • Spring
    • Java

Spring Batch

Website:

Http://www.springsource.org/spring-batch

Download page:

Http://static.springsource.org/spring-batch/downloads.html

Document:

Http://static.springsource.org/spring-batch/reference/index.html

database table creation Connection: DDL

Http://static.springsource.org/spring-batch/reference/html/metaDataSchema.html#exampleDDLScripts

Chapter 1, Introducing Spring Batch

Spring batch requires a relational database to run, and in its official documentation, in the appendix, there is a database table structure that creates its dependencies.

The goal of the spring batch design:

1. Big Data processing

2, automation of

3. Robust

4. Trustworthy

5, high-performance

The size of the commit-interval= "100" in the chunk in the configuration file is the size of the chunk block. They are one thing.

Chunk inside there is Itemreader itemprocessor Itemwriter, Itemreader read one record at a time, itemprocessor processing a record once, Itemwriter one input commit-interval= "100" specifies the number of records (that is, the size of the chunk block) of the object size.

The recommended size of the Commit-interval is 10 to 200. If this value is too large, if it is output data to the database, it will cause the database of things too big data, affecting the performance of the database, the database will record a lot of rollback data content, resulting in poor performance. This value is too small and causes many transactions to occur, resulting in slow spring batch operation.

Parameters that can be run using the spel dynamic configuration program, for example:

<property name= "Resource" value= "file:#{jobparameters[' Inputresource ']}"/>

One thing to note here is that the bean's scope must be "step". Spel expressions are supported in spring 3.x.

<bean id= "Reader" class= "Org.springframework.batch.item.file.FlatFileItemReader" scope= "Step" >

The following is the metadata table for spring batch, the DDL for the Oracle database

SQL code
  1. CREATE TABLE batch_job_instance (
  2. job_instance_id number (19,0) not NULL PRIMARY KEY,
  3. VERSION number (19,0),
  4. Job_name VARCHAR2 (+) not NULL,
  5. Job_key VARCHAR2 (+) not NULL,
  6. constraint Job_inst_un unique (job_name, job_key)
  7. ) ;
  8. CREATE TABLE batch_job_execution (
  9. job_execution_id number (19,0) not NULL PRIMARY KEY,
  10. VERSION number (19,0),
  11. job_instance_id number (19,0) is not NULL,
  12. Create_time TIMESTAMP not NULL,
  13. Start_time TIMESTAMP DEFAULT NULL,
  14. End_time TIMESTAMP DEFAULT NULL,
  15. STATUS VARCHAR2 (10),
  16. Exit_code VARCHAR2 (100),
  17. Exit_message VARCHAR2 (2500),
  18. last_updated TIMESTAMP,
  19. constraint JOB_INST_EXEC_FK foreign Key (job_instance_id)
  20. references Batch_job_instance (job_instance_id)
  21. ) ;
  22. CREATE TABLE Batch_job_params (
  23. job_instance_id number (19,0) is not NULL,
  24. TYPE_CD VARCHAR2 (6) not NULL,
  25. Key_name VARCHAR2 (+) not NULL,
  26. String_val VARCHAR2 (250),
  27. Date_val TIMESTAMP DEFAULT NULL,
  28. Long_val number (19,0),
  29. Double_val number,
  30. constraint JOB_INST_PARAMS_FK foreign Key (job_instance_id)
  31. references Batch_job_instance (job_instance_id)
  32. ) ;
  33. CREATE TABLE batch_step_execution (
  34. step_execution_id number (19,0) not NULL PRIMARY KEY,
  35. VERSION number (19,0) is not NULL,
  36. Step_name VARCHAR2 (+) not NULL,
  37. job_execution_id number (19,0) is not NULL,
  38. Start_time TIMESTAMP not NULL,
  39. End_time TIMESTAMP DEFAULT NULL,
  40. STATUS VARCHAR2 (10),
  41. Commit_count number (19,0),
  42. Read_count number (19,0),
  43. Filter_count number (19,0),
  44. Write_count number (19,0),
  45. Read_skip_count number (19,0),
  46. Write_skip_count number (19,0),
  47. Process_skip_count number (19,0),
  48. Rollback_count number (19,0),
  49. Exit_code VARCHAR2 (100),
  50. Exit_message VARCHAR2 (2500),
  51. last_updated TIMESTAMP,
  52. constraint JOB_EXEC_STEP_FK foreign Key (job_execution_id)
  53. references Batch_job_execution (job_execution_id)
  54. ) ;
  55. CREATE TABLE Batch_step_execution_context (
  56. step_execution_id number (19,0) not NULL PRIMARY KEY,
  57. Short_context VARCHAR2 (2500) not NULL,
  58. Serialized_context CLOB,
  59. constraint STEP_EXEC_CTX_FK foreign Key (step_execution_id)
  60. references Batch_step_execution (step_execution_id)
  61. ) ;
  62. CREATE TABLE Batch_job_execution_context (
  63. job_execution_id number (19,0) not NULL PRIMARY KEY,
  64. Short_context VARCHAR2 (2500) not NULL,
  65. Serialized_context CLOB,
  66. constraint JOB_EXEC_CTX_FK foreign Key (job_execution_id)
  67. references Batch_job_execution (job_execution_id)
  68. ) ;
  69. CREATE SEQUENCE batch_step_execution_seq START with 0 MINVALUE 0 MAXVALUE 9223372036854775807 nocycle;
  70. CREATE SEQUENCE batch_job_execution_seq START with 0 MINVALUE 0 MAXVALUE 9223372036854775807 nocycle;
  71. CREATE SEQUENCE batch_job_seq START with 0 MINVALUE 0 MAXVALUE 9223372036854775807 nocycle;

Notes SQL scripts are available in the core Jar package of Spring batch. For example: Spring-batch-core-2.1.9.release.jar's core package Org.springframework.batch.core, Schema-drop-[database].sql In the form of SQL scripts that provide a variety of mainstream relational databases.

The databases supported by spring batch are: Derby, H2, Hsqldb,mysql, Oracle, PostgreSQL, SQL Server, and Sybase.

Chapter 2, Spring Batch Concepts

1. main components of Spring batch:

Job repository The underlying component of the persistence job execution metadata

Job launcher The underlying component of the boot job execution

Application Components for Jobbatch processing

A word within the stepjob, a job consisting of a series of step
Tasklet, repeatable processing steps for applying transactions in step

Item a record entered or output from the data source

Chunk a list of item sizes of the specified size.

Item Reader is responsible for reading the component of the item record from the data source

Item processor is responsible for handling (conversion, validation, filtering, etc.) Item record components

Item writer is responsible for outputting a chunk item to the data source: the component that outputs the list of specified size items to the data source

2. How the spring batch interacts with the external

External Cron,quartz, such as scheduling, or the Web, can call launch, triggering the operation of spring batch.

3, the basic components of Spring batch include: Job launch and Job repository. They do not require developer development, they need to be configured in configuration files only.

The job of Spring batch is a series of step components in the spring batch XML.

4, the use of Tasklet

Create a step, including writing a tasklet execution or using a tasklet provided by a spring batch.

When you need to unzip a file, call a stored procedure, or delete a file, call the SH script, you need to create your own Tasklet implementation.

When implementing Tasklet, these requirements can be divided into batch read-process-write mode, then the chunk element should be used to configure Tasklet as chunk processing processing steps. The chunk element allows your program to read, process, and write data more efficiently.

Summary: Job is a series of steps (step) that you can easily define in spring batch XML. The steps (step) are composed of Tasklet. Tasklet can be made up of "module-oriented" Chunk, or Tasklet is completely customizable by developers.

5. Job Related Concepts

A, job work

b, job instance work example

c, job execution execution

A job can have many work instances (job instance), and each work instance (job instance) can have a lot of work execution (job execution).

In spring batch, the work instance (job instance) includes work (job) and work parameters (job parameter).

Java code
    1. Joblauncher.run (Job, new Jobparametersbuilder ()
    2. . addstring ("date", "2010-06-27")
    3. . Tojobparameters ()
    4. );

Work Example equation:

Jobinstance = Job + job-parameters.

Some rules for the life cycle of job instance and job execution:

A. When you run the job for the first time, spring batch creates the job instance and the first job execution.

b, you cannot run the job instance again after the same job instance was successfully executed.

C, you cannot execute multiple identical instances at the same time.

================ Basic Part End ============================

Spring Batch (i): Basic section

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.