Skip to content

Commit 20eaa7b

Browse files
committed
Clarify ChunkListener changes in v6
Resolves #5226
1 parent 9ccbafa commit 20eaa7b

2 files changed

Lines changed: 15 additions & 17 deletions

File tree

spring-batch-core/src/main/java/org/springframework/batch/core/listener/ChunkListener.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,16 @@ default void afterChunkError(ChunkContext context) {
8181
}
8282

8383
/**
84-
* Callback before the chunk is processed, inside the transaction. This method is not
85-
* called in concurrent steps.
84+
* Callback after a chunk is read but before it is processed, inside the transaction.
85+
* <strong>This method is not called in concurrent steps.</strong>
8686
* @since 6.0
8787
*/
8888
default void beforeChunk(Chunk<I> chunk) {
8989
}
9090

9191
/**
92-
* Callback after the chunk is written, inside the transaction. This method is not
93-
* called in concurrent steps.
92+
* Callback after the chunk is written, inside the transaction. <strong>This method is
93+
* not called in concurrent steps.</strong>
9494
* @since 6.0
9595
*/
9696
default void afterChunk(Chunk<O> chunk) {
@@ -100,7 +100,7 @@ default void afterChunk(Chunk<O> chunk) {
100100
* Callback if an exception occurs while processing or writing a chunk, inside the
101101
* transaction, which is about to be rolled back. <em>As a result, you should use
102102
* {@code PROPAGATION_REQUIRES_NEW} for any transactional operation that is called
103-
* here</em>. This method is not called in concurrent steps.
103+
* here</em>. <strong>This method is not called in concurrent steps.</strong>
104104
* @param exception the exception that caused the underlying rollback.
105105
* @param chunk the processed chunk
106106
* @since 6.0

spring-batch-docs/modules/ROOT/pages/step/chunk-oriented-processing/intercepting-execution.adoc

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,33 +103,31 @@ The annotations corresponding to this interface are:
103103
A "`chunk`" is defined as the items processed within the scope of a transaction. Committing a
104104
transaction, at each commit interval, commits a chunk. You can use a `ChunkListener` to
105105
perform logic before a chunk begins processing or after a chunk has completed
106-
successfully, as the following interface definition shows:
106+
successfully or in failure, as the following interface definition shows:
107107

108108
[source, java]
109109
----
110-
public interface ChunkListener extends StepListener {
110+
public interface ChunkListener<I, O> extends StepListener {
111111
112-
void beforeChunk(ChunkContext context);
113-
void afterChunk(ChunkContext context);
114-
void afterChunkError(ChunkContext context);
112+
void beforeChunk(Chunk<I> chunk);
113+
void afterChunk(Chunk<O> chunk);
114+
void afterChunkError(Exception exception, Chunk<O> chunk);
115115
116116
}
117117
----
118118

119-
The beforeChunk method is called after the transaction is started but before reading begins
120-
on the `ItemReader`. Conversely, `afterChunk` is called after the chunk has been
121-
committed (or not at all if there is a rollback).
119+
The `beforeChunk` method is called after the transaction is started after reading a chunk
120+
of items but before processing start. Conversely, `afterChunk` is called after the chunk
121+
is written but before the transaction is committed or rolled back.
122+
123+
NOTE: The `ChunkListener` listener interface is not called in concurrent steps
122124

123125
The annotations corresponding to this interface are:
124126

125127
* `@BeforeChunk`
126128
* `@AfterChunk`
127129
* `@AfterChunkError`
128130

129-
You can apply a `ChunkListener` when there is no chunk declaration. The `TaskletStep` is
130-
responsible for calling the `ChunkListener`, so it applies to a non-item-oriented tasklet
131-
as well (it is called before and after the tasklet).
132-
133131
A `ChunkListener` is not designed to throw checked exceptions. Errors must be handled in the
134132
implementation or the step will terminate.
135133

0 commit comments

Comments
 (0)