How to conditionally enable or disable scheduled jobs in Spring?

前端 未结 11 1412
轻奢々
轻奢々 2020-11-28 07:26

I am defining scheduled jobs with cron style patterns in Spring, using the @Scheduled annotation.

The cron pattern is stored in a config properties file

11条回答
  •  鱼传尺愫
    2020-11-28 07:59

    You can group schedule methods by conditions into number of services and init them like this:

    @Service
    @ConditionalOnProperty("yourConditionPropery")
    public class SchedulingService {
    
    @Scheduled
    public void task1() {...}
    
    @Scheduled
    public void task2() {...}
    
    }
    

提交回复
热议问题