# spring-boot-demo-task-quartz > 此 demo 主要演示了 Spring Boot 如何集成 Quartz 定时任务,并实现对定时任务的管理,包括新增定时任务,删除定时任务,暂停定时任务,恢复定时任务,修改定时任务启动时间,以及定时任务列表查询。 ## 后端 ### 初始化 在 `init/dbTables` 下选择 Quartz 需要的表结构,然后手动创建表。 ### pom.xml ```xml 4.0.0 spring-boot-demo-task-quartz 1.0.0-SNAPSHOT jar spring-boot-demo-task-quartz Demo project for Spring Boot com.xkcoding spring-boot-demo 1.0.0-SNAPSHOT UTF-8 UTF-8 1.8 2.1.0 1.2.10 org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-quartz tk.mybatis mapper-spring-boot-starter ${mybatis.mapper.version} com.github.pagehelper pagehelper-spring-boot-starter ${mybatis.pagehelper.version} mysql mysql-connector-java org.springframework.boot spring-boot-starter-test test cn.hutool hutool-all com.google.guava guava org.projectlombok lombok true spring-boot-demo-task-quartz org.springframework.boot spring-boot-maven-plugin ``` ### application.yml ```yaml server: port: 8080 servlet: context-path: /demo spring: # 省略其余配置,具体请 clone 本项目,查看详情 # ...... quartz: # 参见 org.springframework.boot.autoconfigure.quartz.QuartzProperties job-store-type: jdbc wait-for-jobs-to-complete-on-shutdown: true scheduler-name: SpringBootDemoScheduler properties: org.quartz.threadPool.threadCount: 5 org.quartz.threadPool.threadPriority: 5 org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread: true org.quartz.jobStore.misfireThreshold: 5000 org.quartz.jobStore.class: org.quartz.impl.jdbcjobstore.JobStoreTX org.quartz.jobStore.driverDelegateClass: org.quartz.impl.jdbcjobstore.StdJDBCDelegate # 在调度流程的第一步,也就是拉取待即将触发的triggers时,是上锁的状态,即不会同时存在多个线程拉取到相同的trigger的情况,也就避免的重复调度的危险。参考:https://segmentfault.com/a/1190000015492260 org.quartz.jobStore.acquireTriggersWithinLock: true # 省略其余配置,具体请 clone 本项目,查看详情 # ...... ``` --- > 后端其余代码请 clone 本项目,查看具体代码 ## 前端 > 前端页面请 clone 本项目,查看具体代码 ## 启动 1. clone 本项目 2. 初始化表格 3. 启动 `SpringBootDemoTaskQuartzApplication.java` 4. 打开浏览器,查看 http://localhost:8080/demo/job.html ![image-20181126214007372](http://static.xkcoding.com/spring-boot-demo/task/quartz/064006-1.jpg) ![image-20181126214109926](http://static.xkcoding.com/spring-boot-demo/task/quartz/064008.jpg) ![image-20181126214212905](http://static.xkcoding.com/spring-boot-demo/task/quartz/064009-1.jpg) ![image-20181126214138641](http://static.xkcoding.com/spring-boot-demo/task/quartz/064009.jpg) ![image-20181126214250757](http://static.xkcoding.com/spring-boot-demo/task/quartz/064007.jpg) ## 参考 - Spring Boot 官方文档:https://docs.spring.io/spring-boot/docs/2.1.0.RELEASE/reference/htmlsingle/#boot-features-quartz - Quartz 官方文档:http://www.quartz-scheduler.org/documentation/quartz-2.2.x/quick-start.html - Quartz 重复调度问题:https://segmentfault.com/a/1190000015492260 - 关于Quartz定时任务状态 (在 `QRTZ_TRIGGERS` 表中的 `TRIGGER_STATE` 字段) ![image-20181126171110378](http://static.xkcoding.com/spring-boot-demo/task/quartz/064006.jpg) - Vue.js 官方文档:https://cn.vuejs.org/v2/guide/ - Element-UI 官方文档:http://element-cn.eleme.io/#/zh-CN