簡體   English   中英

Spring Batch Job Scheduler

[英]Spring Batch Job Scheduler

有沒有辦法為通過XML配置的特定Spring Batch作業指定調度程序,而無需使用utils RunScheduler類,例如: https ://www.mkyong.com/spring-batch/spring-batch-and-spring-taskscheduler-example/?

所以現在我的配置看起來像這樣:

 <batch:job id="testJob" job-repository="jobRepository" parent="jobParent">
        <batch:step id="testStep" allow-start-if-complete="true">
            <batch:tasklet>
                <batch:chunk
                        reader="testReader"
                        processor="testProcessor"
                        writer="jmsWriter">
                </batch:chunk>
            </batch:tasklet>
        </batch:step>
    </batch:job>


 <task:scheduled-tasks>
        <task:scheduled ref="testJobLauncher" method="runJob" cron="0 */5 * * * *"/>
    </task:scheduled-tasks>

    <bean id="testJobLauncher"
          class="com.test.RunScheduler"
          p:job-ref="testJob"
          p:jobLauncher-ref="jobLauncher"
     "/>



@Component
public class RunScheduler {

    private JobLauncher jobLauncher;
    private Job job;

    public void runJob() {
        try {
            String dateParam = new Date().toString();
                JobParameters param = new JobParametersBuilder().addString("date", dateParam).toJobParameters();
                JobExecution execution = jobLauncher.run(job, param);               
        } catch (Exception e) {
            LOGGER.error("Can't start job", e);
            throw new RuntimeException(e);
        }
    }

    public Job getJob() {
        return job;
    }

    public void setJob(Job job) {
        this.job = job;
    }

    public JobLauncher getJobLauncher() {
        return jobLauncher;
    }

    public void setJobLauncher(JobLauncher jobLauncher) {
        this.jobLauncher = jobLauncher;
    }

}

有沒有辦法不使用RunScheduler類,而僅使用XML config處理它?

您可以將@EnableScheduling和cronSequenceGenerator的功能用於調度和cron設置,而無需依賴util類。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM