Lesson 10: Configuration, Resource Usage and SchedulerFactory

http://www.quartz-scheduler.org/documentation/quartz-1.x/tutorials/TutorialLesson10

The architecture of Quartz is modular, and therefore to get it running several components need to be "snapped" together. Fortunately, some helpers exist for making this happen.

The major components that need to be configured before Quartz can do its work are:

  • ThreadPool
  • JobStore
  • DataSources (if necessary)
  • The Scheduler itself

The ThreadPool provides a set of Threads for Quartz to use when executing Jobs. The more threads in the pool, the greater number of Jobs that can run concurrently. However, too many threads may bog-down your system. Most Quartz users find that 5 or so threads are plenty- because they have fewer than 100 jobs at any given time, the jobs are not generally scheduled to run at the same time, and the jobs are short-lived (complete quickly). Other users find that they need 10, 15, 50 or even 100 threads - because they have tens-of-thousands of triggers with various schedules - which end up having an average of between 10 and 100 jobs trying to execute at any given moment. Finding the right size for your scheduler's pool is completely dependent on what you're using the scheduler for. There are no real rules, other than to keep the number of threads as small as possible (for the sake of your machine's resources) - but make sure you have enough for your Jobs to fire on time. Note that if a trigger's time to fire arrives, and there isn't an available thread, Quartz will block (pause) until a thread comes available, then the Job will execute - some number of milliseconds later than it should have. This may even cause the tread to misfire - if there is no available thread for the duration of the scheduler's configured "misfire threshold".

A ThreadPool interface is defined in the org.quartz.spi package, and you can create a ThreadPool implementation in any way you like. Quartz ships with a simple (but very satisfactory) thread pool named org.quartz.simpl.SimpleThreadPool. This ThreadPool simply maintains a fixed set of threads in its pool - never grows, never shrinks. But it is otherwise quite robust and is very well tested - as nearly everyone using Quartz uses this pool.

JobStores and DataSources were discussed in Lesson 9 of this tutorial. Worth noting here, is the fact that all JobStores implement the org.quartz.spi.JobStore interface - and that if one of the bundled JobStores does not fit your needs, then you can make your own.

Finally, you need to create your Scheduler instance. The Scheduler itself needs to be given a name, told its RMI settings, and handed instances of a JobStore and ThreadPool. The RMI settings include whether the Scheduler should create itself as an RMI server object (make itself available to remote connections), what host and port to use, etc.. StdSchedulerFactory (discussed below) can also produce Scheduler instances that are actually proxies (RMI stubs) to Schedulers created in remote processes.

StdSchedulerFactory

StdSchedulerFactory is an implementation of the org.quartz.SchedulerFactory interface. It uses a set of properties (java.util.Properties) to create and initialize a Quartz Scheduler. The properties are generally stored in and loaded from a file, but can also be created by your program and handed directly to the factory. Simply calling getScheduler() on the factory will produce the scheduler, initialize it (and its ThreadPool, JobStore and DataSources), and return a handle to its public interface.

There are some sample configurations (including descriptions of the properties) in the "docs/config" directory of the Quartz distribution. You can find complete documentation in the "Configuration" manual under the "Reference" section of the Quartz documentation.

DirectSchedulerFactory

DirectSchedulerFactory is another SchedulerFactory implementation. It is useful to those wishing to create their Scheduler instance in a more programmatic way. Its use is generally discouraged for the following reasons: (1) it requires the user to have a greater understanding of what they're doing, and (2) it does not allow for declarative configuration - or in other words, you end up hard-coding all of the scheduler's settings.

Logging

Logging

Quartz uses the SLF4J framework for all of its logging needs. In order to "tune" the logging settings (such as the amount of output, and where the output goes), you need to understand the SLF4J framework, which is beyond the scope of this document.

If you want to capture extra information about trigger firings and job executions, you may be interested in enabling theorg.quartz.plugins.history.LoggingJobHistoryPlugin and/or org.quartz.plugins.history.LoggingTriggerHistoryPlugin.

Quartz Enterprise Job Scheduler 1.x Tutorial---转载的更多相关文章

  1. Quartz使用(2) - Quartz核心接口Scheduler、Job

    quartz的核心接口如下: 接口 含义 Scheduler scheduler的主要API接口 Job 任务实现接口,期望调度器能够执行 JobDetail 用于定义Job实例 Trigger 调度 ...

  2. quartz多个scheduler实现

    1.首先排除错误用法 SchedulerFactory schedulerFactory = new StdSchedulerFactory(); Scheduler scheduler = sche ...

  3. Quartz源码——scheduler.start()启动源码分析(二)

    scheduler.start()是Quartz的启动方式!下面进行分析,方便自己查看! 我都是分析的jobStore 方式为jdbc的SimpleTrigger!RAM的方式类似分析方式! Quar ...

  4. Enterprise Library系列文章目录(转载)

    1. Microsoft Enterprise Library 5.0 系列(一) Caching Application Block (初级) 2. Microsoft Enterprise Lib ...

  5. spring quartz 的定时器cronExpression表达式写法(转载)

    转载来源:https://zhidao.baidu.com/question/240797777248343764.html====================================== ...

  6. A re-introduction to JavaScript (JS Tutorial) 转载自:https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript

    A re-introduction to JavaScript (JS Tutorial) Redirected from https://developer.mozilla.org/en-US/do ...

  7. SpringBoot多任务Quartz动态管理Scheduler,时间配置,页面+源码

    页面展现 后台任务处理:恢复任务 15s执行一次后台打印消息 不BB了,直接上代码 import... /** * 调度工厂类 * Created by jinyu on 2018/4/14/014. ...

  8. 几种任务调度的 Java 实现方法与比较Timer,ScheduledExecutor,Quartz,JCronTab

    几种任务调度的 Java 实现方法与比较 综观目前的 Web 应用,多数应用都具备任务调度的功能.本文由浅入深介绍了几种任务调度的 Java 实现方法,包括 Timer,Scheduler, Quar ...

  9. java 多线程——quartz 定时调度的例子

    java 多线程 目录: Java 多线程——基础知识 Java 多线程 —— synchronized关键字 java 多线程——一个定时调度的例子 java 多线程——quartz 定时调度的例子 ...

随机推荐

  1. uva 12526 - Cellphone Typing

    字典树,可惜比赛的时候有两句话写倒了: 害得我调了一个小时: 今天不宜做题 = = 代码: #include<cstdio> #include<cstring> #define ...

  2. Server-Side Access Control

    Firefox 3.5 implements the W3C Access Control specification.  As a result, Firefox 3.5 sends specifi ...

  3. DZ的伪静态神马的终于OK了

    十分感谢开发“凤凰图集”的onexin团队!帮忙搞定了伪静态!这玩意儿折腾了俺好多功夫,人家瞬间就搞定.

  4. 3D触控简介:建立数字刻度应用及快速活动栏

    苹果公司通过 iPhone 6s 和 6s Plus 引入了与手机互动的全新方式:按压手势.你也许知道,苹果智能手表和苹果笔记本电脑早已具备这一功能,只是名称略有不同,为力感触控(Force Touc ...

  5. 设计模式之策略模式Strategy

    /** * 策略设计模式 * 策略模式:定义一系列的算法族,使他们之间可以相互转换,动态的改变其行为. * 问题:设计一个鸭子模拟游戏. * 现在有一群鸭子: * ①这些鸭可以有飞的行为(分为快和慢) ...

  6. Android ListView异步加载数据

    1.主Activity public class MainActivity extends Activity { private ListView listView; private ArrayLis ...

  7. 谈谈SpringMVC Validation

    2016-10-12 19:26:08,897 [INFO ] [http-nio-8032-exec-1] HttpHeaderValidator:84 - HttpHeaderValidator. ...

  8. poj2104

    裸的主席树,没什么好说的 type node=record        l,r,s:longint;      end; ..] of node;     sa,rank,a,b,sum,head: ...

  9. Unity3D游戏开发入门(一)

    视频: 慕课网适合入门 http://www.imooc.com/video/6582 蛮牛网: http://www.manew.com/ 圣殿中文手册 5.3.2破解工具 面试题 pdf 书籍:

  10. dfs 生成排列和组合

    利用深度优先搜索的性质可以方便的生成n的排列和组合,但是生成组合时每个组合里面元素的个数必须事先确定,以前以为生成组合跟排列一样到n时就可以回溯,直到今天做了某题之后才发现那是错的,那样做生成不了所有 ...