我想使用Spring中的Scheduled在上午8:00和每天3:10 Pm执行Job

时间:2018-05-28 09:55:12

标签: spring spring-mvc spring-scheduled

我在春天使用@Scheduled,如果我想在evey上执行任务,那么它将正常工作5秒使用@Scheduled(fixedRate = 5000) 但我想在上午8:00和每天3:10 Pm执行Job,这是无效的。 以下是我的代码。

@Component
public class FinanceJob  {

    @Autowired
    AdminService adminService;

    @Autowired
    AdminDao dao;

    @Autowired
    CommonService cservice;


    //@Scheduled(fixedRate = 5000)

    // @Scheduled(cron = "0/20 * * * * ?")
    @Scheduled(cron="0 48 2 * * *",zone = "Indian/Maldives")
    public void sajan() {
        List<SystemParameter> paramList=cservice.getSysParam();

        for(SystemParameter param :paramList)
        {
            if(param.getUid()==263 && param.getIsactive()==1)
            {
                System.out.println("Hello Sahjan");
            }
        }

    }

}

1 个答案:

答案 0 :(得分:0)

AFAIK,您无法通过两个select id, name, SUM(lastDay.unitsSold) as latDayUnitsSold, SUM(lastMonth.unitsSold) as latMonthUnitsSold, SUM(lastYear.unitsSold) as latYearUnitsSold, from `products` left join `productStats` as `lastDay` on `products`.`id` = `lastDay`.`productId` and `lastDay`.`time` between '2018-05-27 00:00:00' and '2018-05-28 00:00:00' left join `productStats` as `lastMonth` on `products`.`id` = `lastMonth`.`productId` and `lastDay`.`time` between '2018-04-28 00:00:00' and '2018-05-28 00:00:00' left join `productStats` as `lastYear` on `products`.`id` = `lastYear`.`productId` and `lastDay`.`time` between '2017-05-28 00:00:00' and '2018-05-28 00:00:00' group by `products`.`id` 时间表安排工作。

您可以做的是包装您的任务并通过其他功能公开计划:

cron