简单功能——简单描述,不喜无忧
主要介绍:Spring Task 、 Quartz 、年月日时分秒周的设置、 两者对比
一、Spring Task
Spring从3.0开始增加了自己的任务调度器,它是通过扩展java.util.concurrent包下面的类来实现的,使用起来较为简便;
注解方式实现:
首先增加命名空间schema
<beans xmlns="http://www.springframework.org/schema/beans"
......
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="
......
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-4.1.xsd"
其次,让spring能够扫描到
<task:annotation-driven/>
最后定时任务执行方法
@Component(“taskJob”)
public class TaskJob {
@Scheduled(cron = "0 0 3 * * ?")
public void job1() {
System.out.println(“任务进行中。。。”);
}
}
XML配置方式实现
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:task="http://www.springframework.org/schema/task"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.s