Spring自带的定时器task

xiaoxiao2021-02-27  153

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执行一次

转载请注明原文地址: https://www.6miu.com/read-16027.html

最新回复(0)