前言
在很多公司,特别是互联网公司,需要在指定的时间进行一些跑批任务来完成业务实现,Java中实现定时的方式有很多,其中可自己实现,也有比较成熟的框架,如: Quartz,今天来介绍一下Quartz的使用,
简述
Quartz is a richly featured, open source job scheduling library that can be integrated within virtually any Java application - from the smallest stand-alone application to the largest e-commerce system. Quartz can be used to create simple or complex schedules for executing tens, hundreds, or even tens-of-thousands of jobs; jobs whose tasks are defined as standard Java components that may execute virtually anything you may program them to do. The Quartz Scheduler includes many enterprise-class features, such as support for JTA transactions and clustering.
Quartz是一个功能丰富的开源作业框架,可以集成到几乎任何的Java应用程序中,从最小的独立应用程序或最大的电商系统,Quartz可用于创建数十,数百甚至数十万个简单的作业或复杂的计划,任务定义为标准的Java组件业务,可以执行几乎任何可以对其进行编程的任务,Quartz Scheduler包含许多企业级功能,例如: 支持JTA事务和集群。
功能
- 支持集群,故障转移
- 精确可控的任务调度
- 事务支持等
更多功能请参考: http://www.quartz-scheduler.org/overview/features.html
环境准备
该项目使用intellij IDE+Maven作为开发开发工具。
quartz maven依赖:
1 2 3 4 5 6 7 8 9 10 11 12 |
<!-- quartz start--> <dependency> <groupId>org.quartz-scheduler</groupId> <artifactId>quartz</artifactId> <version>2.3.0</version> </dependency> <dependency> <groupId>org.quartz-scheduler</groupId> <artifactId>quartz-jobs</artifactId> <version>2.3.0</version> </dependency> <!--quartz end--> |
quartz中使用slf4j作为日志工具。
log maven依赖为:
1 2 3 4 5</ |