如何从主班上调用调度程序

发布于 2025-01-28 17:18:27 字数 319 浏览 5 评论 0原文

我的应用程序每天有两个调度程序在特定时间每天运行,每天每天进行1小时的时间间隔。 我在deploy.yaml中添加了cron表达式,而无需使用调度程序标签。我正在呼叫app.java ..的第一个调度程序..但是现在我对第二个调度程序感到困惑我打算使用交换机实施。有人可以帮助我。

Deploy.yaml`spec: scheduler:* * * * * *`

Public class job2 {Public void job2function() {}`}`}`

Public class job1 { `public void job1fun(){}`}`}`

My application have two schedulers one runs every day at a particular time and another scheduler every day at and interval of 1 hour.
I have added the cron expression in deploy.Yaml without using the scheduler tag.I am calling the first scheduler from App.java..But now I am confused about the second scheduler how can I call the second scheduler in App.java.I am planning to implement with a switch.can someone help me on this please.What I am trying is to route to the scheduler using Java configuration without using XML Configuration

Deploy.yaml`spec: scheduler:* * * * * *`

Public class job2 {Public void job2function() {}`}`}`

Public class job1 { `public void job1fun(){}`}`}`

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蒲公英的约定 2025-02-04 17:18:27

您可以为调度程序作业定义2个组件。

@Component    
public class Job1 {
    @Scheduled(cron = "${job1.cron.expression:0 2 1 * * ?}")
    public void running() {
        // implementation
    }
}

@Component    
public class Job2 {
    @Scheduled(cron = "${job2.cron.expression:0 1 1 * * ?}")
    public void running() {
        // implementation
    }
}

Spring Boot将自动安排相关组件作为要运行的工作。

在上面的cron表达式中,它可以在您的deploy.yaml文件中进行自定义以指定它们。

Deploy.yaml:

......
applications:
  env:
    job2.cron.expression: '0 2 1 * * ?'
    job1.cron.expression: '0 1 1 * * ?'
.......

请尝试。

You can define your 2 components for the scheduler job.

@Component    
public class Job1 {
    @Scheduled(cron = "${job1.cron.expression:0 2 1 * * ?}")
    public void running() {
        // implementation
    }
}

@Component    
public class Job2 {
    @Scheduled(cron = "${job2.cron.expression:0 1 1 * * ?}")
    public void running() {
        // implementation
    }
}

Spring boot will automatically scheduled the related components as a job to run.

And in the above cron expression, it can e customized in your deploy.yaml file to specify them.

deploy.yaml:

......
applications:
  env:
    job2.cron.expression: '0 2 1 * * ?'
    job1.cron.expression: '0 1 1 * * ?'
.......

Please try it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文