Get ahead
VMware offers training and certification to turbo-charge your progress.
Learn moreI am pleased to announce that Spring Batch 6.0.0-M2
is available now from Maven Central!
In this milestone release, we shipped the following features and improvements:
For the complete list of changes, please check the release notes.
In this milestone release, the Spring dependencies are upgraded to the following versions:
Please note that this release is compatible with Java 17+.
This is not a new feature, but rather a new, enhanced implementation of the chunk-oriented processing model. This new implementation was introduced as an experimental addition in version 5.1, and is now available as stable in version 6.0.
The new implementation is provided in the ChunkOrientedStep
class, which is a replacement for the ChunkOrientedTasklet
/ TaskletStep
classes.
Here is an example of how to define a ChunkOrientedStep
by using its builder:
@Bean
public Step chunkOrientedStep(JobRepository jobRepository, JdbcTransactionManager transactionManager,
ItemReader<Person> itemReader, ItemProcessor<Person, Person> itemProcessor, ItemWriter<Person> itemWriter) {
int chunkSize = 100;
return new ChunkOrientedStepBuilder<Person, Person>(jobRepository, transactionManager, chunkSize)
.reader(itemReader)
.processor(itemProcessor)
.writer(itemWriter)
.build();
}
Moreover, fault-tolerance features were adapted as follows:
SkipPolicy
interfaceHere is a quick example of how to use the retry and skip features with the new ChunkOrientedStep
:
@Bean
public Step faulTolerantChunkOrientedStep(JobRepository jobRepository, JdbcTransactionManager transactionManager,
ItemReader<Person> itemReader, ItemProcessor<Person, Person> itemProcessor, ItemWriter<Person> itemWriter) {
// retry policy configuration
int maxAttempts = 10;
var retrybaleExceptions = Set.of(TransientException.class);
RetryPolicy retryPolicy = RetryPolicy.builder()
.maxAttempts(maxAttempts)
.includes(retrybaleExceptions)
.build();
// skip policy configuration
int skipLimit = 50;
var skippableExceptions = Set.of(FlatFileParseException.class);
SkipPolicy skipPolicy = new LimitCheckingItemSkipPolicy(skipLimit, skippableExceptions);
// step configuration
int chunkSize = 100;
return new ChunkOrientedStepBuilder<Person, Person>(jobRepository, transactionManager, chunkSize)
.reader(itemReader)
.processor(itemProcessor)
.writer(itemWriter)
.faultTolerant()
.retryPolicy(retryPolicy)
.skipPolicy(skipPolicy)
.build();
}
Please refer to the migration guide for more details on how to migrate from the previous implementation to the new one.
Prior to v6, if a job execution fails abruptly, it was not possible to recover it without a manual database update. This was error-prone and not consistent across different job repositories (as it required a few SQL statements for JDBC databases and some custom statements for NoSQL stores).
This milestone release introduces a new method named recover
in the JobOperator
interface that allows you to recover failed job executions consistently across all job repositories.
I would like to thank all contributors who had a role in this release! As we continue our work on Spring Batch 6, we look forward to your feedback on Github Issues, Github Discussions and X.