spring定时器

1.spring的定时器功能,

//==============================================
//执行类,每五秒执行一次

@Service
@EnableScheduling
public class TimerTest {
    
    @Scheduled(cron="0/5 * * * * ?")
    public void run(){
        System.out.println("定时器。。。。。。。。。");
    }
}

//==============================================
//在spring主配置文件(applicationContext.xml<可能会改名字,配置aop、tx的xml>)中,进行配置
  

 1> 约束声明
        xmlns:task="http://www.springframework.org/schema/task"
        xsi:schemaLocation= "http://www.springframework.org/schema/task
        http://www.springframework.org/schema/task/spring-task.xsd"
    2> 开启@Scheduled注解支持
        <task:annotation-driven />
        
    也可进行非注解的方式进行,两者均可,都可进行参数配置
    
//==================================================
详细内容参见(转): http://blog.csdn.net/qq_33556185/article/details/51852537
//===================================================
tips:如果多个定时任务开启,需要配置线程池。

原文地址:https://www.cnblogs.com/nnn123/p/6807772.html