@Scheduled注解 Spring定时任务

1:在spring-content.xml添加配置文件
xmlns:task="http://www.springframework.org/schema/task"
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-4.1.xsd
2:配置线程池


3:配置开关

4:java代码体现
@Scheduled(cron="0 0/3 * * * ?")//严格定义三分钟执行一次
public void execute() {
   try{
      (主体方法)
      }catch(Exception e){


      logger.error("服务器异常"+e.getMessage());
   }

}

你可能感兴趣的:(Java)