Skip to content

Commit 9bd4b51

Browse files
committed
Fix documentation of chunk-oriented processing
Resolves #1629 #1179 #1069 #3833 (cherry picked from commit 3fbfbb9)
1 parent f7e6eab commit 9bd4b51

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed
Loading
Loading

spring-batch-docs/asciidoc/step.adoc

+39-6
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,61 @@ image::{batch-asciidoc}images/step.png[Step, scaledwidth="60%"]
2727

2828
Spring Batch uses a 'Chunk-oriented' processing style within its most common
2929
implementation. Chunk oriented processing refers to reading the data one at a time and
30-
creating 'chunks' that are written out within a transaction boundary. One item is read in
31-
from an `ItemReader`, handed to an `ItemProcessor`, and aggregated. Once the number of
30+
creating 'chunks' that are written out within a transaction boundary. Once the number of
3231
items read equals the commit interval, the entire chunk is written out by the
3332
`ItemWriter`, and then the transaction is committed. The following image shows the
3433
process:
3534

3635
.Chunk-oriented Processing
3736
image::{batch-asciidoc}images/chunk-oriented-processing.png[Chunk Oriented Processing, scaledwidth="60%"]
3837

39-
The following code shows the same concepts shown:
38+
The following pseudo code shows the same concepts in a simplified form:
4039

4140
[source, java]
4241
----
4342
List items = new Arraylist();
4443
for(int i = 0; i < commitInterval; i++){
45-
Object item = itemReader.read()
46-
Object processedItem = itemProcessor.process(item);
47-
items.add(processedItem);
44+
Object item = itemReader.read();
45+
if (item != null) {
46+
items.add(item);
47+
}
4848
}
4949
itemWriter.write(items);
5050
----
5151

52+
A chunk-oriented step can also be configured with an optional `ItemProcessor`
53+
to process items before passing them to the `ItemWriter`. The following image
54+
shows the process when an `ItemProcessor` is registered in the step:
55+
56+
.Chunk-oriented Processing with Item Processor
57+
image::{batch-asciidoc}images/chunk-oriented-processing-with-item-processor.png[Chunk Oriented Processing With Item Processor, scaledwidth="60%"]
58+
59+
The following pseudo code shows how this is implemented in a simplified form:
60+
61+
[source, java]
62+
----
63+
List items = new Arraylist();
64+
for(int i = 0; i < commitInterval; i++){
65+
Object item = itemReader.read();
66+
if (item != null) {
67+
items.add(item);
68+
}
69+
}
70+
71+
List processedItems = new Arraylist();
72+
for(Object item: items){
73+
Object processedItem = itemProcessor.process(item);
74+
if (processedItem != null) {
75+
processedItems.add(processedItem);
76+
}
77+
}
78+
79+
itemWriter.write(processedItems);
80+
----
81+
82+
For more details about item processors and their use cases, please refer to the
83+
<<processor.adoc#itemProcessor,Item processing>> section.
84+
5285
[[configuringAStep]]
5386
==== Configuring a `Step`
5487

src/models/Figures.ppt

1.33 MB
Binary file not shown.

0 commit comments

Comments
 (0)