I am trying to create a Spring batch job using ListItemReader<String> , ItemProcessor<String, String> and ItemWriter<String> .
XML is as follows:
<job id="sourceJob" xmlns="http://www.springframework.org/schema/batch"> <step id="step1" next="step2"> <tasklet> <chunk reader="svnSourceItemReader" processor="metadataItemProcessor" writer="metadataItemWriter" commit-interval="1" /> </tasklet> </step> <step id="step2"> <tasklet ref="lastRevisionLoggerTasklet"></tasklet> </step> </job> <bean id="svnSourceItemReader" class="com.example.repository.batch.SvnSourceItemReader" scope="prototype"> <constructor-arg index="0"> <list> <value>doc1.xkbml</value> <value>doc2.xkbml</value> <value>doc3.xkbml</value> </list> </constructor-arg> </bean> <bean id="metadataItemProcessor" class="com.example.repository.batch.MetadataItemProcessor" scope="prototype" /> <bean id="metadataItemWriter" class="com.example.repository.batch.MetadataItemWriter" scope="prototype" />
The reader, processor, and writer are vanilla,
public class SvnSourceItemReader extends ListItemReader<String> { public SvnSourceItemReader(List<String> list) { super(list); System.out.println("Reading data list " + list); } @Override public String read() { String out = (String) super.read(); System.out.println("Reading data " + out); return out; } } public class MetadataItemProcessor implements ItemProcessor<String, String> { @Override public String process(String i) throws Exception { System.out.println("Processing " + i + " : documentId " + documentId); return i; } } public class MetadataItemWriter implements ItemWriter<String> { @Override public void write(List<? extends String> list) throws Exception { System.out.println("Writing " + list); } }
Work starts as follows, but on a schedule every 10 seconds.
long nanoBits = System.nanoTime() % 1000000L; if (nanoBits < 0) { nanoBits *= -1; } String dateParam = new Date().toString() + System.currentTimeMillis() + "." + nanoBits; param = new JobParametersBuilder().addString("date", dateParam) .toJobParameters(); JobExecution execution = jobLauncher.run(job, param);
When the application starts, I see that it reads, processes, and writes each of the three elements in the list passed to the reader.
Reading data doc1.xkbml Processing doc1.xkbml : documentId doc1 Writing [doc1.xkbml] Reading data doc2.xkbml Processing doc2.xkbml : documentId doc2 Writing [doc2.xkbml] Reading data doc3.xkbml Processing doc3.xkbml : documentId doc3 Writing [doc3.xkbml]
Since this sourceJob is on the scheduled timer, every 10 seconds I expected to see that this list has been processed, but instead I see on all subsequent launches.
Reading data null
Does anyone know why this is happening? I am new to Spring Batch and just cant deal with the problem.
Thanks / w