【发布时间】:2014-01-27 09:48:29
【问题描述】:
我有一个基本的 spring 批处理作业 (spring-core-3.1.1) 应用程序设置,使用石英调度程序 (1.8.6) 运行。它看起来像这样,
- spring batch job has a mysql datasource to save job states in spring batch schema
- job Reader is a csvFile reader using class org.springframework.batch.item.file.FlatFileItemReader
- Writer is simple custom ItemWriter (output is on console)
- quartz scheduler is used to setup crontrigger alongwith jobdetail bean
- scheudler runs the job every 10 seconds (*/10 * * * * ?)
我想通过读取 CSV 文件来自定义此设置,每个作业实例仅读取 X 行,而不是读取整个文件,例如如果文件中有 10 行,并且我想每步读取 2 行,那么作业实例应该只读取 2 行而不是 10 行。为此,我想根据读取的行数为作业提供动态参数。这样对于每个作业执行,作业实例都具有唯一且递增的参数。就像文件阅读器的光标一样。
如何实现?
参数的我的 jobdetail 属性
<property name="jobDataAsMap">
<map>
<entry key="jobName" value="reportJob" />
<entry key="jobLocator" value-ref="jobRegistry" />
<entry key="jobLauncher" value-ref="jobLauncher" />
<entry key="cursor" value="0"/>
<!-- Gives error on this one: <entry key="cursor" value="#{jobParameters['cursor']}"/>
</map>
</property>
【问题讨论】:
标签: spring spring-mvc parameters quartz-scheduler spring-batch