spring-projects / spring-projects/spring-batch
Chunck Monitor always report a warn about restarting, even if restart is desactivated
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 3k
- Forks
- 2.5k
- Avg merge
- 6d 53m
- Merged PRs (30d)
- 3
Description
Bug description
I use a RepositoryItemReader in a multi-thread scope (with a task executor)
RepositoryItemReader is thread safe, and as documented I set up : .saveState(false) and manage my state in my own code.
Environment
Java 21
SpringBoot 3.3.0
SpringBatch 5.1.2
Hibernate 6.5.2
Steps to reproduce
Run my Job and the WARN logs are showed: ItemStream was opened in a different thread. Restart data could be compromised.
Expected behavior
No warn about state when save state is disabled.
Minimal Complete Reproducible example
Please provide a failing test or a minimal complete verifiable example that reproduces the issue.
Bug reports that are reproducible will take priority in resolution over reports that are not reproducible.
My Step:
@Bean(name = "snapshotAccountPositionStep")
@JobScope
public Step cobAccounts(JobRepository jobRepository,
PlatformTransactionManager transactionManager,
@Qualifier("batchThreadPool") TaskExecutor taskExecutor,
SnapshotAccountPositionProcessor processor,
@Qualifier("snapshotListener") SnapshotAccountPositionStepListener snapshotListener,
@Value("${job.skipLimit}") int skipLimit,
@Value("${job.chunkSize}") int chunkSize) {
return new StepBuilder("snapshotAccountPositionStep", jobRepository)
.<TSIDResult, String>chunk(chunkSize, transactionManager)
.faultTolerant()
.skip(JobErrorStepListener.JobProcessingException.class)
.skipLimit(skipLimit)
.taskExecutor(taskExecutor)
.reader(workAccountReader(null, null, null))
.processor(processor)
.listener(snapshotListener)
.listener(getPatchListener())
.writer(accountWriter())
.listener(getErrorListener(null, null))
.build();
}
My reader:
@Bean
@StepScope
public RepositoryItemReader<TSIDResult> workAccountReader(CobAccountWorkRepository repository,
@Value("${positionSnapshot.readerPageSize}") Integer readerPageSize,
@Value("#{jobParameters['date']}") LocalDate date) {
return new RepositoryItemReaderBuilder<TSIDResult>()
.name("workAccountReader")
.saveState(false)
.repository(repository)
.methodName("findByStatusInAndDate")
.arguments(List.of(TO_DO, DONE), date)
.sorts(Collections.singletonMap(date.ID, Sort.Direction.ASC))
.pageSize(readerPageSize)
.build();
}
// ChunkMonitor.java
private ChunkMonitorData getData() {
ChunkMonitorData data = holder.get();
if (data == null) {
if (streamsRegistered) {
logger.warn("ItemStream was opened in a different thread. Restart data could be compromised.");
}
data = new ChunkMonitorData(0, 0);
holder.set(data);
}
return data;
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with ChunkMonitor.java and its getData() method, then trace how streamsRegistered relates to the RepositoryItemReader configured with saveState(false). Reproduce the task-executor scenario if possible and inspect existing Spring Batch tests for chunk monitoring. Done means the warning is not emitted when restart state is disabled, while relevant restart warnings remain covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring-boot
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100