Quartz Enterprise Job Scheduler 1.x Tutorial---转载

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.

时间: 2024-11-02 22:13:22

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

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

quartz的核心接口如下: 接口 含义 Scheduler scheduler的主要API接口 Job 任务实现接口,期望调度器能够执行 JobDetail 用于定义Job实例 Trigger 调度器基于特定时间来执行指定任务的组件 JobBuilder 用于定义.创建JobDetail实例 TriggerBuilder 用于定义.创建Trigger实例 1. Scheduler 一个调度器的生命周期为通过SchedulerFactory创建,直到执行其shutdown()方法.当Schedu

quartz 浅谈 Scheduler

1.Scheduler工厂模式 所有的Scheduler实例应该由SchedulerFactory来创建 2.SchedulerFactory类图   最常用的是StdSchedulerFactory工程类,其出那个键Scheduler的两种方式: //3. 创建scheduler Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler(); // 3. 创建scheduler SchedulerFactory sfact =

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

java 多线程 目录: Java 多线程——基础知识 Java 多线程 —— synchronized关键字 java 多线程——一个定时调度的例子 java 多线程——quartz 定时调度的例子 java 多线程—— 线程等待与唤醒 概述 第1部分 配置 第2部分 代码示例 第1部分 配置 有关quartz的api文档地址:Quartz Enterprise Job Scheduler 1.8.6 API 主要接口目录: 重点看下Job,Scheduler,Trigger,JobDetai

Quartz入门指南

看到官网的教程对于新手来说不够全面和连贯,因此结合自己的使用过程写下这个入门指南,用以解惑.本文基于Quartz2.2.2版本.请注意,本文为了易于上手,省略了许多重要的概念,建议阅读Quartz2.2.x官方教程. 一.安装与配置 下载.解压后,进入lib文件夹,将所有jar文件放入项目指定目录,然后在BuildPath中添加.Jar包共6个,如下所示. Quartz的运行依赖于log4j.xml和quartz.properties这两个配置文件.关于它们的配置方法,请查阅各自官网.我们偷个懒

项目中使用Quartz集群分享--转载

项目中使用Quartz集群分享--转载 在公司分享了Quartz,发布出来,希望大家讨论补充. CRM使用Quartz集群分享  一:CRM对定时任务的依赖与问题  二:什么是quartz,如何使用,集群,优化  三:CRM中quartz与Spring结合使用 1:CRM对定时任务的依赖与问题  1)依赖  (1)每天晚上的定时任务,通过sql脚本 + crontab方式执行 Xml代码   #crm 0 2 * * * /opt/***/javafiles/***/shell/***_dail

Quartz.NET - Quartz.NET Quick Start Guide

转自:http://www.quartz-scheduler.net/documentation/quartz-2.x/quick-start.html Quartz.NET Quick Start Guide Welcome to the Quick Start Guide for Quartz.NET. As you read this guide, expect to see details of: Downloading Quartz.NET Installing Quartz.NET

Quartz.NET syudy

Quartz.NET Quartz.NET是一个开源的作业调度框架,是OpenSymphony 的 Quartz API的.NET移植,它用C#写成,可用于winform和asp.net应用中.它提供了巨大的灵活性而不牺牲简单性.你能够用它来为执行一个作业而创建简单的或复杂的调度.它有很多特征,如:数据库支持,集群,插件,支持cron-like表达式等等.        你曾经需要应用执行一个任务吗?这个任务每天或每周星期二晚上11:30,或许仅仅每个月的最后一天执行.一个自动执行而无须干预的任

Quartz.NET简介及入门指南

Quartz.NET简介 Quartz.NET是一个功能完备的开源调度系统,从最小的应用到大规模的企业系统皆可适用. Quartz.NET是一个纯净的用C#语言编写的.NET类库,是对非常流行的JAVA开源调度框架 Quartz 的移植. 入门指南 本入门指南包括以下内容: 下载 Quartz.NET 安装 Quartz.NET 根据你的特定项目配置 Quartz 启动一个样例程序 下载和安装 你可以下载 zip 文件或使用 Nuget 程序包.Nuget 程序包只包含 Quartz.NET 运

The first talk about what is Quartz.Net

正如标题所示,文章主要是围绕Quartz.Net作业调度框架话题展开的,内容出自博主学习官方Examples的学习心得与体会,文中难免会有错误之处,还请指出得以指教. 在百度一下搜索Quartz.Net,可以知道Quartz.Net是Net版本的任务调度框架,是一个从java移植过来的Net版本的开源框架,在作业调度方面提供了很好的灵活性而不牺牲简单,能够为执行一个作业而创建简单的或复杂的调度,目前版本支持数据库,集群,插件配置,支持cron表达式等等 Quartz Enterprise Sch