DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • How To Propagate Context Information Throw Spring Batch
  • High-Performance Batch Processing Using Apache Spark and Spring Batch
  • Batch Processing Large Data Sets with Spring Boot and Spring Batch
  • Migrating COBOL Batch to Spring Batch

Trending

  • The Big Data Architecture Blueprint: Core Storage, Integration, and Governance Patterns
  • Spring AI Advisors: Chat Memory, Token Tracking, and Message Logging
  • Why Your Test Automation Is Always Behind the Code And the Architecture That Fixes It
  • Operationalizing Enterprise AI at Scale: Architecture, Governance, and Adoption
  1. DZone
  2. Culture and Methodologies
  3. Career Development
  4. An Introduction to Spring Batch

An Introduction to Spring Batch

Want to learn more about using Spring Batch to run large amounts of data on your application? Click here to learn more in this post on Spring Batch using Quartz.

By 
Sagar Pandit user avatar
Sagar Pandit
·
Aug. 07, 18 · Tutorial
Likes (12)
Comment
Save
Tweet
Share
42.5K Views

Join the DZone community and get the full member experience.

Join For Free

Are you in a state where your application needs to process a large amount of data in a bunch,  generate reports, or run batches for business purposes? Then, this article will tell you how to do it using Spring Batch. First, let's take a look at batch processing:

Batch processing is a processing mode that involves the execution of a series of automated, complex jobs without user interaction. A batch process handles bulk data and runs for a long time.

Now, what is Spring Batch? Spring Batch is a light framework that is used to develop batch applications for the following usages:

  1. Transaction management

  2. Job-processing statistics

  3. Job restart, etc.

Consider the diagram below:

Image title

The above diagram represents a Spring Batch flow. As can be seen here, we have several modules. Let's go one-by-one through each module.

1. JobRepository: This represents the persistence of batch meta-data entities in the database.It acts as a repository  that contains batch jobs' information, for example, when the last batch job was run, etc.

Below is the XML configuration of the  JobRepository :

<bean id = "jobRepository" class = "org.springframework.batch.core.repository.support.JobRepositoryFactoryBean">
    <property name = "dataSource" ref = "dataSource" />
    <property name = "transactionManager" ref="transactionManager" />
    <property name = "databaseType" value = "mysql" />
</bean>


2. JobLauncher:  This is an interface used to launch a job or run jobs when the jobs' scheduled time arrives. It takes the jobs name and some other parameters while launching or running the job.

3. Job: This is the main module, which consist of the business logic to be run.

4. Step: Steps are nothing but an execution flow of the job. A complex job can be divided into several steps or chunks, which can be run one after another or ran depending on the result of the previous steps. 

5. ItemReader: This interface is used to perform bulk-reading of data, e.g. reading several lines of data from an Excel file when a job starts

6.ItemProcessor: When the data is read using itemreader, ItemProcessor  can be used to perform the processing of data, depending on the business logic.

7. ItemWriter: This interface is used to write bulk data — either to a database or any other file disks.

This article gives some basic understanding of Spring Batch. Many of the real-world applications use Spring Batch with Quartz triggers to perform their batch operations. I will give you a little idea here about what is actually running Spring Batch using Quartz.

Quartz has a modular architecture. It consists of several basic components that can be combined as required. In this tutorial, we’ll focus on the ones that are common to every job: Job, JobDetail, Trigger and Scheduler.

  •  Job, as described above, is nothing but the business logic that we need to execute when it runs

  •  JobDetail: This conveys the detailed properties of the job instance, such as the name of job, the jobClass, which is used to run the job, a map setting, and the other properties of the job, like the JobLaunchername of the group to which job belongs.

  •  Trigger: These are used to start the jobs when the job time arrives. It is used to trigger the job execution. We can use various types of triggers. The most common is the Cron trigger, which sets the cron expressions, for example, when the job is to be run.

  •  Scheduler: The Scheduler  contains all the above modules. It sets the triggers and the job details. The Scheduler should have a unique job name for all the jobs to be run.

This will give you a basic understanding of the modules related when you want to run Spring Batch applications using Quartz.

Spring Batch Spring Framework career

Opinions expressed by DZone contributors are their own.

Related

  • How To Propagate Context Information Throw Spring Batch
  • High-Performance Batch Processing Using Apache Spark and Spring Batch
  • Batch Processing Large Data Sets with Spring Boot and Spring Batch
  • Migrating COBOL Batch to Spring Batch

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook