Skip to content

An experiment with a Spring Batch job running the processor step in parallel

Notifications You must be signed in to change notification settings

felipe-gdr/spring-batch-parallel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring Batch with parallel processing

This is a simple example of a Spring Batch job running in parallel, leveraging the Multi-Threaded step with synchronized reader strategy.

Running the application

  1. mvn install
  2. execute experiments.sync.App

An example of output we get from executing App:

Example output

As we can see, parallel execution is much, much faster than the async version.

How to make a sync job parallel

It's super easy. There are only 2 simple steps:

1. Configure the tasklet to run with a TaskExecutor

<bean id="taskExecutor" class="org.springframework.core.task.SimpleAsyncTaskExecutor"/>
    
<batch:tasklet
        task-executor="taskExecutor"
        throttle-limit="20">
    <batch:chunk
            reader="basicItemReader"
            processor="compositeProcessor"
            writer="basicItemWriter"
            commit-interval="10">
    </batch:chunk>
</batch:tasklet>

2. Make the Reader's read method synchronized

@Override
public synchronized Item read() throws ItemReaderException {
    return items.poll();
}

Resources

About

An experiment with a Spring Batch job running the processor step in parallel

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages