Top Spring Batch Interview Questions (2020) | CodeUsingJava

Most frequently Asked Spring Batch Interview Questions



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.

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 Partioning in such a scenario.