Spring Batch interview questions for experienced

  • by

In this page I have covered top Spring Batch interview questions for 2, 3, 4, or 5 and above years of experience. I am including questions and answers regularly here. So bookmark this page by hitting CTRL+D. Thanks for reading..

Q1. What are the two ways a step can be processed? Explain them.

Ans: Tasklet and Chunk are the two ways to process a step in Spring Batch. This is the first thing you need to tell when they ask about the explanation or two elaborate the difference between tasklet and chunk. So, let’s see them in elaborate.

Tasklet: Though not commonly used, Tasklet is a single task that needs to be executed. It is used in case of simple and granular tasks like deleting a resource or executing a query. Also note that aggregation is not involved for tasklet task execution.

Chunk: Now it is clear that chunk is direct opposite to Tasklet. Chunk processing involves complex tasks involving reads, processing and writes the we use chunk oriented processing. Its the most common way of executing a Step. Usually used in scenarios like copying, processing and transferring of data.

Q2. How does a tasklet defined in a Spring Batch application?

Ans:A tasklet performs a single task in a step. A tasklet can be defined by using Tasklet interface.

Example:
public class LinesWriter implements Tasklet {
/* class definition goes here */
}

Q3. What is the common problem faced in using tasklet approach for batch processing?

Ans: Consider the case where the data being processed by the batch processing is larger. In these scenario, memory problem may occur and assume that there is a particular point in the processing where the application has got an exception.

Now we need to re-start the entire processing again and that too with no guarantee that it will succeed with no exception next time.

Q4. Which approach is good compared to Tasklet and chunk in Spring batch?

Ans: Both the different approach technically. There are best used at their suited situations. At one scenario Tasklet may be preferred over chunk. On scenarios of high volume of data, processing X amount of data records using chunk approach is a good move.

So, to state exactly, these approaches plays good at their situations. Review your solution to the problem and use them accordingly.

Q5. Give an real world example where Spring Batch is preferably used.

Ans: Unlike the regular application model like serving request as a web service or running as a workstation application, the batch processing application model utilizes batch processing framework to perform complex computation intense processing over data. Some of the processing includes reading and writing to and from different data sources such a file, database or a remote stream source.

Tasks like create reports, import and export data and things like that are often preferred to be implemented on top of a framework like Spring Batch. Spring Boot 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.

One should also leverage the framework as a highly scalable manner to process significant volumes of information if required.

How useful was this post?

Click on a star to rate it!

Average rating 3 / 5. Vote count: 2

We are sorry that this post was not useful for you!

Let us improve this post!

Leave a Reply

Welcome to CloudiKnow.com blog, a platform to share knowledge and solution experience related to public cloud is base design of this site.

You can start the cloud journey right from here!
Please bookmark this page by pressing simply CTRL+D.