一种Scheduled异常原因
使用场景本来想写一个一个月执行一次的定时任务,运行后报错如下
@Scheduled(fixedRate = 1000 * 60 * 60 * 24 * 30)
public void task() throws ParseException, IOException
Caused by: java.lang.IllegalStateException: Encountered invalid @Scheduled method ‘task’: Exactly one of the ‘cron’, ‘fixedDelay(String)’, or ‘fixedRate(String)’ attributes is required
表面看是写的必须有且只有一个周期定义,源码调试后发现fixRate值为-1702967296,明显是越界了,声明时改为long如下即可恢复正常。
@Scheduled(fixedRate = 1000l * 60 * 60 * 24 * 30)