Spring自带的定时器task 非常好用
不需要在配置文件中配置,只需要注解就可以实现
例:
import org.jeecgframework.web.monitoring.Service.MonitoringService;
import org.jeecgframework.web.monitoring.pojo.MonitoringBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
/**监控模块
* @author wuqiwei
*
*/
@Component
public class MonitoringController {
@Scheduled(cron = "5 * * * * ?")
//@Scheduled(fixedDelay = 5000)
public void MonitoringMethod() {
System.out.println("Method executed at every 5 seconds. Current time is :: " + (new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date()));
}
}5S执行一次
本文介绍如何使用Spring框架自带的定时任务功能,通过简单的注解即可实现定时任务的配置与执行。示例展示了每5秒执行一次的方法。

1万+

被折叠的 条评论
为什么被折叠?



