Spring Batch step without explicit commit interval

ID

java.spring_batch_explicit_commit_interval

Severity

info

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Reliability

Language

Java

Tags

best-practice, reliability, spring

Description

Reports Spring Batch step configurations that use tasklet() without a preceding chunk() call. Without an explicit commit interval, the step executes in a single transaction, which may cause memory exhaustion or long-running database locks.

Rationale

A tasklet-based step in Spring Batch runs its execute method repeatedly until it returns RepeatStatus.FINISHED, all within a single transaction boundary. For large data sets this means the entire processing happens without intermediate commits, risking OutOfMemoryError and lock escalation.

// Bad - no explicit commit interval
stepBuilderFactory.get("step1")
    .tasklet(myTasklet)
    .build();

Remediation

Use chunk-oriented processing with an explicit commit interval.

// Good - processes in chunks of 100
stepBuilderFactory.get("step1")
    .<Input, Output>chunk(100)
    .reader(reader)
    .processor(processor)
    .writer(writer)
    .build();