Giter Club home page Giter Club logo

springboot-quartz's Introduction

SpringBoot整合Quartz作为调度中心使用完整实例

本例是一个将quartz集成为调度器中心的典型示例,主要用于定时执行一些Job(通常是一些自定义程序或者可执行的jar包),基于Spring Boot 2.0.1,Quartz 2.2.3。

如果你只是想要简单的SpringBoot整合Quartz,对定时任务进行 自定义逻辑,启动,暂停,恢复,删除,修改。 可以参考 : https://github.com/EalenXie/springboot-quartz-simple (这个例子相当于算是个整合Quartz入门的例子,我也做了完整和详细的注释说明)

1. 本例基本的实现效果: 定时执行一些可执行的Job

运行效果如图 :

avatar

看到这里,说明Quartz集群已经搭建成功了。如果部署该项目应用到多个服务器上面,Job会在多个服务器上面执行,但同一个Job只会在某个服务器上面执行,即如果服务器A在某个时间执行了某个Job,则其他服务器如B,C,D在此时间均不会执行此Job。即不会造成该Job被多次执行。

avatar

这里可以看到数据库中的Job已经在Quartz注册并初始化成功了,Scheduler也在工作了,Job也已经按照cron在定时执行。

avatar

本例中,如果job包含一个jar的路径,并且该jar包是一个可执行的JOB,则可以看到该JOB的运行情况 :

avatar

看到JOB已经执行完成了 :

avatar

此时如果在数据库中手动修改某个Job的执行cron,并不会马上生效,则可以调用上面写到的业务方法,/refresh/all,则可刷新所有的Job,或/refresh/{id},刷新某个Job。

2. 在你启动该应用之前:

  1. 请自行修改数据库配置: /application.yml

  2. 请准备Quartz的元数据表 : quartz_innodb.sql

  3. 请为这个例子的Job配置准备一个表 : job_entity.sql

  4. 如果想要查看真实的jar包运行,请准备一个真实的jar包路径,并且该jar包是可执行的(有主程序运行清单),并设置该JOB的状态为OPEN。

3. 原创不易,感谢支持 :

本例博客说明链接 : https://www.cnblogs.com/ealenxie/p/9134602.html

springboot-quartz's People

Contributors

ealenxie avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.