'How to call scheduler from Main Class

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(){}`}`}`


Solution 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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1