弹簧批处理作业参数重复运行

时间:2014-01-27 09:48:30

标签: spring spring-mvc parameters quartz-scheduler spring-batch

我有一个使用quartz scheduler(1.8.6)运行的基本弹簧批处理作业(spring-core-3.1.1)应用程序设置。它看起来像这样,

     - 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 * * * * ?)

我想通过只读取每个作业实例的X行数而不是读取整个文件的CSV文件来自定义此设置。如果一个文件中有10行,并且我想每步读取2行,则作业实例应该只读取2行而不是10个atonce。为此,我想根据读取的行数给出作业动态参数。因此,对于每个作业执行,作业实例都具有唯一且递增的参数。就像光标到文件阅读器一样。

如何实现它?

我的param

的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>

1 个答案:

答案 0 :(得分:0)

您可以阅读最新成功完成的作业参数以检测最新的起始行,然后将2添加到此值并调用新作业 您可以使用JobExplorer读取作业表元数据,也可以直接查询spring-batch的meta-data tables