Bug description
JdbcPagingItemReader and JpaPagingItemReader create the internal results list as a CopyOnWriteArrayList:
if (results == null) {
results = new CopyOnWriteArrayList<>();
} else {
results.clear();
}
However, paging readers are strictly single-threaded.
AbstractPagingItemReader#doRead() already serializes access with an internal lock:
this.lock.lock();
try {
...
} finally {
this.lock.unlock();
}
Because there is no concurrent access to results, using CopyOnWriteArrayList provides no benefit and introduces unnecessary write-cost overhead. A regular ArrayList is sufficient and more appropriate for this use case.
This is not a functional bug, but the current choice of collection does not match the actual access pattern of the readers.
Environment
- Spring Batch version: 6.0.0
- Java version: Java 21
Expected behavior
Since paging readers operate in a single-threaded, sequential manner, the internal list should use ArrayList instead of CopyOnWriteArrayList.