This section shows the major highlights of Spring Batch 5.1.
What’s New in Spring Batch 5.1
Spring Batch 5.1 introduces the following features:
Dependencies upgrade
In this release, the Spring dependencies are updated to the following versions:
-
Spring Framework 6.1.0-M2
-
Spring Integration 6.2.0-M1
-
Spring Data 3.2.0-M1
-
Spring LDAP 3.2.0-M1
-
Micrometer 1.12.0-M1
Virtual Threads support
Embracing JDK 21 LTS is one of the main themes for Spring Batch 5.1, especially the support of virtual threads from Project Loom. In this release, virtual threads can be used in all areas of the framework, like running a concurrent step with virtual threads or launching multiple steps in parallel using virtual threads.
Thanks to the well designed separation of concerns in Spring Batch, threads are not managed directly. Thread
management is rather delegated to TaskExecutor
implementations from Spring Framework. This programming-to-interface
approach allows you to switch between TaskExecutor
implementations in a transparent and a flexible way.
In Spring Framework 6.1, a new TaskExecutor
implementation based on virtual threads has been introduced, which is the
VirtualThreadTaskExecutor
. This TaskExecutor
can be used in Spring Batch wherever a TaskExecutor
is required.
Memory management improvement in the JpaItemWriter
When using the JpaItemWriter
, the JPA persistence context can quickly grow when the chunk size
is large enough. This might lead to OutOfMemoryError
errors if not cleared appropriately in a timely manner.
In this release, a new option named clearPersistenceContext
has been introduced in the JpaItemWriter
to clear the persistence context after writing each chunk of items. This option improves the memory management
of chunk-oriented steps dealing with large amounts of data and big chunk sizes.
New synchronized decorators for item readers and writers
Up to version 5.0, Spring Batch provided two decorators SynchronizedItemStreamReader
and SynchronizedItemStreamWriter
to synchronize thread access to ItemStreamReader#read
and ItemStreamWriter#write
. Those decorators are useful when
using non thread-safe item streams in multi-threaded steps.
While those decorators work with ItemStream
implementations, they are not usable with non-item streams. For example,
those decorators cannot be used to synchronize access to ListItemReader#read
or KafkaItemWriter#write
.
For users convenience, this release introduces new decorators for non-item streams as well. With this new feature, all item readers and writers in Spring Batch can now be synchronized without having to write custom decorators.