@@ -27,28 +27,61 @@ image::{batch-asciidoc}images/step.png[Step, scaledwidth="60%"]
27
27
28
28
Spring Batch uses a 'Chunk-oriented' processing style within its most common
29
29
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
32
31
items read equals the commit interval, the entire chunk is written out by the
33
32
`ItemWriter`, and then the transaction is committed. The following image shows the
34
33
process:
35
34
36
35
.Chunk-oriented Processing
37
36
image::{batch-asciidoc}images/chunk-oriented-processing.png[Chunk Oriented Processing, scaledwidth="60%"]
38
37
39
- The following code shows the same concepts shown :
38
+ The following pseudo code shows the same concepts in a simplified form :
40
39
41
40
[source, java]
42
41
----
43
42
List items = new Arraylist();
44
43
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
+ }
48
48
}
49
49
itemWriter.write(items);
50
50
----
51
51
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
+
52
85
[[configuringAStep]]
53
86
==== Configuring a `Step`
54
87
0 commit comments