Top Spring Batch Interview Questions (2021) | CodeUsingJava
















Most frequently Asked Spring Batch Interview Questions


  1. What is Spring Batch?
  2. What are features of Spring Batch?
  3. What are disadvantages of Spring Batch?
  4. What are use cases of Spring Batch?
  5. How to implement security for Spring Batch?
  6. What is Spring Batch Partitioning?
  7. Explain the conditions processing in Spring Batch?
  8. Explain the Spring Batch framework architecture?
  9. What is ExecutionContext in Spring Batch?
  10. What are the typical processing strategies in Spring Batch?
  11. What is spring batch listener?
  12. How can a person configure a job in Spring Batch framework?
  13. What Is Execution context?
  14. What is difference between Remote Partitioning and Remote Chunking in Spring Batch?
  15. What is Commandline jobrunner in Spring Batch?

What is Spring Batch?

Spring Batch is an open source framework for batch processing. It is a lightweight, comprehensive solution designed to enable the development of robust batch applications. Spring Batch builds upon the POJO-based development approach of the Spring Framework. Spring Batch provides reusable functions that are essential in processing large volumes of records, including logging/tracing, transaction management, job processing statistics, job restart, skip, and resource management.
Spring Boot Batch Hello World Example

What are features of Spring Batch?

The features of Spring Batch are as follows -
  • Transaction management
  • Chunk based processing
  • Declarative I/O
  • Start/Stop/Restart
  • Retry/Skip
  • Web based administration interface

What are disadvantages of Spring Batch?

The disadvantages of Spring Batch are as follows-
  • Spring Batch code is complex. If one does not understand the framework then it can be difficult to understand the flow.
  • The performance will not be good if not preperly implemented
  • Exception handling can be complex.
  • Logs for Spring Batch may not reflect/return the exception or issue we are looking for.


What are use cases of Spring Batch?

  • We can automate complex logic and efficiently process data without user interaction. We can run these jobs daily
  • Bulk data can be processed efficiently
  • Data transformation and other operations can be performed in a transactional operation.

What is Spring Batch Admin ?

Spring Batch Admin provides a web-based user interface (UI) that allows you to manage Spring Batch jobs. Spring Cloud Data Flow is now the recommended replacement for managing and monitoring Spring Batch jobs.

How to implement security for Spring Batch ?

We will need to implement a method to authenicate the user -

public Authentication authenticateUser(String username, String password) {
    ProviderManager providerManager = (ProviderManager)applicationContext.getBean("authenticationManager");
    Authentication authentication = providerManager.authenticate(new UsernamePasswordAuthenticationToken(username, password));
    setAuthentication(authentication);
    return authentication;
}


What is Spring Batch Partitioning ?

In some scenarios single threaded application will may not give proper performance. In such a scenario spring batch partitioning is one way for scaling batch jobs that can improve performance In Spring Batch, "partitioning" is multiple threads to process range of data each. Lets take example, You have 100 records in table, which has primary id assigned from 1 to 100 and you want to access all 100 records. We can make use of Spring Batch Partitioning in such a scenario.
Spring Boot + Batch Partitioning Hello World Example

What is Spring Batch Classifier ?

Spring Batch Classifier is used when there is a need to classify data to multiple files or database based on some conditions. Multiple files can be of different formats.
Spring Boot + Spring Batch Classifier Hello World Example

Explain the conditions processing in Spring Batch?

Spring batch follows the traditional batch architecture where a job repository does the work of scheduling and interacting with the job. A job can have more than one steps and every step typically follows the sequence of reading data, processing it and writing it.Spring Batch provides reusable functions that are essential in processing large volumes of records, including logging transaction management, job processing statistics, job restart, skip, and resource management.
For example, a step may read data from a CSV file process it and write it into the database. Spring Batch provides many made Classes to read/write CSV, XML and database.

Spring Boot + Spring Batch Classifier Hello World Example

What is Spring Batch Job Parameter ?

Spring Batch Classifier is used when there is a need to classify data to multiple files or database based on some conditions. Multiple files can be of different formats.
Spring Boot + Spring Batch Job Parameters Hello World Example

Explain the Spring Batch framework architecture?

Spring Batch is a lightweight, comprehensive batch framework designed to enable the development of robust batch applications vital for the daily operations of enterprise systems. High-volume batch jobs can leverage the framework in a highly scalable manner to process significant volumes of information.
Application-This component contains all the jobs and the code we write using the Spring Batch framework.
Batch Core-This component contains all the API classes that are needed to control and launch a Batch Job.

framework


What is ExecutionContext in Spring Batch?

An ExecutionContext is a set of key-value pairs containing information that is scoped to either StepExecution or JobExecution.Spring Batch persists the ExecutionContext , which helps in cases where you want to restart a batch run.
For example: When a fatal error has occurred, etc.


What are the typical processing strategies in Spring Batch?

  • cessing during offline
  • Concurrent batch or online processing
  • Parallel processing of many different batch or jobs at the same time
  • Partitioning

What is spring batch listener?

Spring Batch listeners are a way of intercepting the execution of a Job or a Step to perform some meaningful operations or logging the progress.
We will see some samples and eventually see the execution of these various listeners.

listener


How can a person configure a job in Spring Batch framework?

A Job in Spring Batch contains a sequence of one or more Steps. Each Step can be configured with the list of parameters/attribute required to execute each step.
next : next step to execute
tasklet : task or chunk to execute. A chunk can be configured with a Item Reader, Item Processor and Item Writer.
decision : Decide which steps need to executed.


What Is Executioncontext?

An ExecutionContext represents a collection of key/value pairs that are persisted and controlled by the framework in order to provide the developers a placeholder to store persistent state that is scoped to a StepExecution or JobExecution.
Execution context (EC) is defined as the environment in which the JavaScript code is executed. By environment, I mean the value of this , variables, objects, and functions JavaScript code has access to at a particular time.


What is difference between Remote Partitioning and Remote Chunking in Spring Batch?

Remote Partitioning allows data to be partitioned and executed parallely. For example, we can say partition is divided into set of data, like if have 30 rows, so first data set would 1-10 rows, second data set will have 11-20 and so on.. Master Step have all meta data like all partition data sets and slave executes those meta data and send result back to master for aggregation.
Remote Chunking read the data and has control to pass the data to its Slaves for processing. Once slaves process data,the result of the ItemProcessor is returned to the master for writing.

What is Commandlinejobrunner in Spring Batch?

CommandLineJobRunner is one of the ways to bootstrap your Spring batch Job. The xml script launching the job needs a Java class main method as as entry point and CommandLineJobRunner helps you to start your job directly using the XML script.
The CommandLineJobRunner performs 4 tasks:
Load the appropriate ApplicationContext.
Parse command line arguments into JobParameters.
Locate the appropriate job based on arguments.
Use the JobLauncher provided in the application context to launch the job.