<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # 使用 Spring `TaskScheduler`進行 Spring Batch 作業調度 > 原文: [https://howtodoinjava.com/spring-batch/job-scheduler-example/](https://howtodoinjava.com/spring-batch/job-scheduler-example/) 在企業應用程序中,您將需要將 **cron 表達式**傳遞給 Spring `TaskScheduler`,在固定的時間表上定期執行 Spring Batch 作業。 在此示例中,我們將使用 spring 的內置調度功能執行[示例 Spring Batch 作業](https://howtodoinjava.com/spring-batch/java-config-multiple-steps/)。 ## 配置批處理作業調度程序 要配置,批處理作業調度分兩個步驟完成: 1. 啟用帶有[`@EnableScheduling`](https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/scheduling/annotation/EnableScheduling.html)注解的調度。 2. 創建帶有[`@Scheduled`](https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/scheduling/annotation/Scheduled.html)注解的方法,并使用 cron 作業提供重復詳細信息。 在此方法內添加作業執行邏輯。 `Cron scheduling on spring batch job` ```java package com.howtodoinjava.demo; import org.springframework.batch.core.Job; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.JobParametersBuilder; import org.springframework.batch.core.launch.JobLauncher; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; @SpringBootApplication @EnableScheduling public class App { @Autowired JobLauncher jobLauncher; @Autowired Job job; public static void main(String[] args) { SpringApplication.run(App.class, args); } @Scheduled(cron = "0 */1 * * * ?") public void perform() throws Exception { JobParameters params = new JobParametersBuilder() .addString("JobID", String.valueOf(System.currentTimeMillis())) .toJobParameters(); jobLauncher.run(job, params); } } ``` 批處理作業將在應用程序啟動后每隔一分鐘運行一次。 > 要引用作業和任務源代碼,請閱讀[ Spring batch Java 配置示例](https://howtodoinjava.com/spring-batch/java-config-multiple-steps/)。 ## 示例 現在,如果您運行該應用程序并驗證日志,您將看到該作業每分鐘都在運行。 `Console` ```java 2018-07-04 15:57:00.073 INFO 7320 --- [pool-1-thread-1] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=demoJob]] launched with the following parameters: [{JobID=1530700020003}] 2018-07-04 15:57:00.097 INFO 7320 --- [pool-1-thread-1] o.s.batch.core.job.SimpleStepHandler : Executing step: [stepOne] MyTaskOne start.. MyTaskOne done.. 2018-07-04 15:57:00.118 INFO 7320 --- [pool-1-thread-1] o.s.batch.core.job.SimpleStepHandler : Executing step: [stepTwo] MyTaskTwo start.. MyTaskTwo done.. 2018-07-04 15:57:00.125 INFO 7320 --- [pool-1-thread-1] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=demoJob]] completed with the following parameters: [{JobID=1530700020003}] and the following status: [COMPLETED] 2018-07-04 15:58:00.007 INFO 7320 --- [pool-1-thread-1] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=demoJob]] launched with the following parameters: [{JobID=1530700080002}] 2018-07-04 15:58:00.011 INFO 7320 --- [pool-1-thread-1] o.s.batch.core.job.SimpleStepHandler : Executing step: [stepOne] MyTaskOne start.. MyTaskOne done.. 2018-07-04 15:58:00.021 INFO 7320 --- [pool-1-thread-1] o.s.batch.core.job.SimpleStepHandler : Executing step: [stepTwo] MyTaskTwo start.. MyTaskTwo done.. 2018-07-04 15:58:00.029 INFO 7320 --- [pool-1-thread-1] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=demoJob]] completed with the following parameters: [{JobID=1530700080002}] and the following status: [COMPLETED] ``` 將我的問題放在評論部分。 學習愉快!
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看