Spring Batch Interview Questions List in 2020

This article is targeted towards providing a comprehensive list of Spring Batch Interview Questions, which are frequently asked in an interview.

A spring batch interview can be easy and difficult, similar to Spring Security interview. It all depends upon the job profile and what interviewer is looking for in the candidate.

So, let’s start with the comprehensive list of questions and answers with numerous examples. These interview questions should be enough for freshers as well as experienced candidates and even tech leads.

Current article is part of our series on Spring Interview Questions.

spring batch interview questions and answers

Spring Batch Interview Questions And Answers

1. What is Spring Batch framework?

Spring Batch is one of the Spring projects which provides a proven and comprehensive framework to create robust Batch Jobs in an easy way and provide support for it.

It is brainchild of commons efforts of Accenture and Pivotal.

2. What is a batch job?

A batch job is a program which typically:

  1. Deals with humongous amount of data in an offline mode.
  2. Reads data from one or multiple sources. Sources can be flat files, databases, streaming messages etc. .
  3. Execute actions on the data. Actions can be transformation, validation, aggregation, applying business rules etc.
  4. Writes data to one or more destinations. Destinations could be same or different than source.

3. Why do we use Spring Batch for Batch processing?

  1. Spring batch framework is created by Accenture team which had years of experience in building batch processing systems and thought to share the knowledge.
  2. The whole project is collaborated by Spring team. So, it works seamlessly with Spring.
  3. The patterns used in the framework are production tested patterns which are available out-of-the box

We can create our own library also but why reinvent the wheel, right?

4. Tell me some of the Spring Batch framework terminologies?

Here are some of the keywords and concepts used in Spring Batch:

  1. Job
  2. Job Instance
  3. Job Execution
  4. Step
  5. Step Execution
  6. Item Reader
  7. Item Processor
  8. Item Writer
  9. Job Launcher

5. Explain Spring Batch framework architecture to me?

Spring Batch architecture consists of 3 layers on high-level:

  1. Application layer
  2. Batch Core layer (contains batch execution environment)
  3. Infrastructure layer
spring batch architecture

Infrastructure Layer consists of fundamental components on which Spring Batch’s Core layer is built-upon. This includes things like Transaction Management, I/O management.

Batch Core Layer consists of framework specific components like Step, Job, JobLauncher, ExecutionContext. Batch core uses the infrastructure layer components.

Application layer consists of application-specific Job scripts which vary from application to application. It uses Batch Core components and sometimes infrastructure layer components directly.

Remarks: One of the most frequently asked Spring Batch Interview Questions.

6. What is Job in Spring Batch framework?

Job is a Spring Batch object which represent a complete batch job.

For example: A daily job(let’s call it LoaderJob), which will load the data from file, validate it and then store it in a database.

Job vs JonInstance vs JobExecution

7. What is JobInstance in Spring Batch framework?

A JobInstance represents Logical Job Run which will then be executed.

Here is the formula for it:

JobInstance = Job + JobParameters

So, one JobInstance is different from another depending upon the JobParameters it is supplied.

For example:

One JobInstance of the above LoaderJob will be to run it on Jan 1, 2020 and second JobInstance of the same Job will be to run it on Jan 2, 2020.

8. What is JobParameters in Spring Batch?

JobParameters is a Spring Batch object which encapsulates the configuration required to run a JobInstance.

For example:

It could have Date and time at which a JobInstance should execute.

Jobparameters example

9. What is JobExecution in Spring Batch?

It is again a Spring Batch object which represents an attempt to run a JobInstance.

For example:

Jan1,2020 JobInstance failed twice for some reason before it completed successfully in third attempt.

So, 1 JobInstance will have 3 JobExecutions.

A JobExecution object hold the statistics, status and other information related to the Job throughout it’s lifetime.

10. What is a Step in Spring Batch Framework?

A Spring Batch Job can be defined as a sequence of Steps.

Thus, A Step represents one of those sequence Steps.

For example:

Earlier mentioned LoaderJob can be defined in 3 Steps:

Step 1: To read the data from the flat files.

Step 2: To validate the read data against some rules.

Step 3: To write the validated data in the database.

step in spring batch

11. What is a StepExecution?

Analogous to JobExecution, a StepExecution represents an attempt to run a Step.

StepExecution object has all the information related to the Step.

It is also linked to the JobExecution of which it is a part.

Note: Spring Batch interview questions on ItemReader, ItemProcessor and ItemWriter are few of the most frequently asked questions.

12. What is an ItemReader?

An ItemReader object represents the input of a Step.

It reads the input one by one and when exhausted returns null.

In 1st Step of LoaderJob, ItemReader will read the flat file lines one by one.

13. What is an ItemProcessor?

An ItemProcessor object represents the processing of input data.

In 2nd Step of LoaderJob, ItemProcessor will apply the business rule on the input data.

14. What is an ItemWriter?

An ItemWriter object represents the output of a Step.

In 3rd Step of LoaderJob, ItemWriter will write the validated data into the database.

15. What is JobLauncher?

Given a Job and JobParameters objects, a JobLauncher object helps in launch of that Job.

Now from here starts some of the advance level Spring Batch Interview Questions which might seem difficult and confusing.

16. What is Tasklet in Spring Batch?

Tasklet is an interface in Spring Batch. The implementation of Tasklet represents a Task which will be executed before or after a Step.

17. What is the difference between Step vs Tasklet vs Chunk?

While Step is an independent phase of execution, Tasklet and Chunk are different processing structures used within a Step.

18. What are different types of process flow for Step execution?

  1. Tasklet Model
  2. Chunk Model

19. Explain Chunk oriented processing.

Reference for further read: Chunk-oriented processing.

20. How to choose between Tasklet model and Chunk model?

Typically, when the Step execution task is simple, we choose Tasklet model and if the task processing is complex, we go for Chunk Model.

21. What is a Spring Scheduler?

Spring Framework provides us abstractions to Schedule a Job at a point of time.

This is a very typical requirement from an application to schedule a number of jobs for specific times and with optional repetition. Spring Scheduling facilitates it.

22. How to setup or configure Spring Batch with Spring Boot?

Checkout this guide for an example of Spring Batch with Spring Boot. It used spring-boot-starter-batch starter dependency.

23. Write a Spring Batch example with Spring Boot.

The above guide explains both configuring spring batch with Spring Boot as well as How to create a batch service.

24. How do I schedule a Spring Batch job?

  1. Enable Scheduling with @EnableScheduling annotation.
  2. Annotate method with @Scheduled annotation.

With this, the method execution will happen at a schedule mentioned in @Scheduled annotation.

For example: @Schedules(cron=”0 */1 * * * ?”) will run after every 1 minute.

With this, we are finished with our list of Spring Batch Interview Questions.

What to read next?

Try our list of Spring Boot Interview Questions or Spring MVC Interview questions.

or checkout our series on Spring Interview Questions and pick the topic necessary to crack the interview.

Leave a Comment