Spring自带的定时器task

来源:互联网 发布:知乎 新ipad和ipadpro 编辑:程序博客网 时间:2024/06/08 14:07

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 * */@Componentpublic 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执行一次

0 0
原创粉丝点击