1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.batch.sample.common;
18
19 import java.util.List;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23 import org.springframework.batch.core.StepExecution;
24 import org.springframework.batch.core.StepExecutionListener;
25 import org.springframework.batch.core.listener.StepExecutionListenerSupport;
26 import org.springframework.batch.item.ItemWriter;
27
28
29
30
31
32
33
34
35
36 public class InfiniteLoopWriter extends StepExecutionListenerSupport implements ItemWriter<Object> {
37
38 private StepExecution stepExecution;
39
40 private int count = 0;
41
42 private static final Log logger = LogFactory.getLog(InfiniteLoopWriter.class);
43
44
45
46
47 @Override
48 public void beforeStep(StepExecution stepExecution) {
49 this.stepExecution = stepExecution;
50 }
51
52
53
54
55 public InfiniteLoopWriter() {
56 super();
57 }
58
59 public void write(List<? extends Object> items) throws Exception {
60 try {
61 Thread.sleep(500);
62 }
63 catch (InterruptedException e) {
64 Thread.currentThread().interrupt();
65 throw new RuntimeException("Job interrupted.");
66 }
67 stepExecution.setWriteCount(++count);
68 logger.info("Executing infinite loop, at count=" + count);
69 }
70 }