欢迎来到石英快速入门指南。 As you read this guide, expect to see details of:当你阅读本指南,希望看到的细节:
- Downloading Quartz下载石英
- Installing Quartz安装石英
- Configuring Quartz to your own particular needs石英配置您自己的特殊需要
- Starting a sample application示例应用程序启动
Download and Installation of Quartz下载和安装的石英
To download Quartz, visit http://www.quartz-scheduler.org/download/ and download the most recent stable release.要下载石英,请访问http://www.quartz-scheduler.org/download/并下载最新的稳定版本。
Once you've downloaded and unpacked the zip file, it's time to install it so that your application can see it.一旦您下载并解压缩文件,它的时间来安装它,让您的应用程序可以看到它。
The Quartz JAR files JAR文件的石英
The Quartz package includes a number of jar files, located in root directory of the distribution.在石英包包含了jar文件的数量,分布根目录中。 The main Quartz library is named quartz-all-xxx.jar (where xxx is a version number).主要石英图书馆被命名为石英全xxx.jar(其中xxx是版本号)。 In order to use any of Quartz's features, this jar must be located on your application's classpath.为了使用的石英的任何功能,这罐必须在您的应用程序的路径位置。
Once you've downloaded Quartz, unzip it somewhere, grab the quartz-all-xxx.jar and put it where you want it.当您下载石英,解压缩到某处,抓住石英全xxx.jar并把它所需的位置。 (If you need information on how to unzip files, go away and learn before you go anywhere near a development environment or the Internet in general. Seriously.) (如果您需要就如何解压缩文件,就离开了,你去之前了解附近的任何地方的发展环境或一般的网络信息。认真。)
I use Quartz primarily within an application server environment, so my preference is to include the Quartz JAR within my enterprise application (.ear or .war file).我用石英主要是在应用服务器环境,所以我的选择是,包括在我的企业应用的石英JAR文件(。耳朵或。war文件)。 However, if you want to make Quartz available to many applications then simply make sure it's on the classpath of your appserver.但是,如果您想使石英提供很多应用程序,然后确保它只是在您的应用服务器类路径的。 If you are making a stand-alone application, place it on the application's classpath with all of the other JARs your application depends upon.如果你正在一独立的应用程序,放置在应用程序与您的应用程序依赖于其他所有类路径的JAR。
Quartz depends on a number of third-party libraries (in the form of jars) which are included in the distribution .zip file in the 'lib' directory.石英取决于第三方库数量(在罐子的形式),这些在分发中。压缩在'lib'文件的目录。 To use all the features of Quartz, all of these jars must also exist on your classpath.若要使用石英的所有功能,所有这些瓶子也必须存在于您的类路径中。 If you're building a standalone Quartz application, I suggest you simply add all of them to the classpath.如果你打算建立一个独立的石英应用程序,我建议你只要全部添加到classpath中。 If you're using Quartz within an app server environment, at least some of the jars will likely already exist on the classpath, so you can afford (if you want) to be a bit more selective as to which jars you include.如果您使用的在一个应用服务器环境中石英,至少罐子有些可能已经存在的路径,这样你就可以负担得起(如果需要)为一点,以你的瓶子包括选择性。

The properties file属性文件
Quartz uses a properties file called (kudos on the originality) quartz.properties . Quartz使用属性文件要求(在创意声望)quartz.properties。 This isn't necessary at first, but to use anything but the most basic configuration it must be located on your classpath.这是没有必要的第一次,但用什么,但它最基本的配置必须在您的类路径位置。
Again, to give an example based on my personal situation, my application was developed using WebLogic Workshop.同样,为了就我个人情况的一个例子,我的应用程序是使用WebLogic Workshop中。 I keep all of my configuration files (including quartz.properties) in a project under the root of my application.我一直在我的应用程序的根我的配置文件(包括quartz.properties在一个项目中)所有。 When I package everything up into a .ear file, the config project gets packaged into a .jar which is included within the final .ear.当我包的一切成一。ear文件,配置到一个项目获得的。jar是在最后包括包装。耳朵。 This automatically puts quartz.properties on the classpath.这会自动将目标路径quartz.properties。
If you're building a web application (ie in the form of a .war file) that includes Quartz, you will likely want to place the quartz.properties file in the WEB-INF/classes folder in order for it to be on the classpath.如果你打算建立一个Web应用程序中的一个。war文件的形式(即),其中包括石英,您可能要放置quartz.properties在WEB-INF/classes文件夹中,以便它是在类路径。
Configuration配置
This is the big bit!这是大一点! Quartz is a very configurable application.石英是一个非常可配置的应用程序。 The best way to configure Quartz is to edit a quartz.properties file, and place it in your application's classpath (see Installation section above).最好的办法是配置石英编辑一个quartz.properties文件,并将其放置在应用程序的类路径(见安装一节段)。
There are several example properties files that ship within the Quartz distribution, particularly under the examples/ directory.有几个例子属性文件,船内的石英分布,特别是在例子/目录。 I would suggest you create your own quartz.properties file, rather than making a copy of one of the examples and deleting the bits you don't need.我建议你创建自己的quartz.properties文件,而不是赚了一个例子拷贝和删除位不需要。 It's neater that way, and you'll explore more of what Quartz has to offer.这是整洁的方式,你将探索有什么石英提供更多。
Full documentation of available properties is available in the Quartz Configuration Reference .可用属性完整的文档可以在石英配置参考 。
To get up and running quickly, a basic quartz.properties looks something like this:为了快速建立和运行,一个基本的quartz.properties看起来像这样:
org.quartz.scheduler.instanceName = MyScheduler org.quartz.scheduler.instanceName = MyScheduler org.quartz.scheduler.instanceId = 1 org.quartz.scheduler.instanceId = 1 org.quartz.scheduler.rmi.export = false org.quartz.scheduler.rmi.export =假 org.quartz.scheduler.rmi.proxy = false org.quartz.scheduler.rmi.proxy =假 org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool org.quartz.threadPool.threadCount = 3 org.quartz.threadPool.threadCount = 3 org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
The scheduler created by this configuration has the following characteristics:在此配置创造的调度有以下特点:
- org.quartz.scheduler.instanceName - It's called "MyScheduler" (doh) org.quartz.scheduler.instanceName -它被称为“MyScheduler”(卫生署)
- org.quartz.scheduler.rmi.export - The scheduler is local, which means it can't be accessed using RMI ( Remote Method Invocation ). org.quartz.scheduler.rmi.export -调度是本地的,这意味着它不能访问使用RMI( 远程方法调用 )。
- org.quartz.threadPool.threadCount - There are 3 threads in the thread pool, which means that a maximum of 3 jobs can be run simultaneously. org.quartz.threadPool.threadCount -有3个线程池,这意味着就业机会的3最多可以同时运行的线程。
- org.quartz.jobStore.class - All of Quartz's data, such as details of jobs and triggers, is held in memory (rather than in a database). org.quartz.jobStore.class -所有的石英的数据,如就业细节,触发器,是在内存中(而不是在一个数据库)。
Even if you have a database and want to use it with Quartz, I suggest you get Quartz working with the RamJobStore before you open up a whole new dimension by working with a database.即使你有一个数据库,并要使用石英它,我建议你石英与RamJobStore工作之前,你打开与数据库的工作一个全新的层面。
Starting a sample application示例应用程序启动
Now you've downloaded and installed Quartz, it's time to get a sample application up and running.现在你已经下载并安装石英,它的时间去一个示例应用程序启动和运行。 The following code obtains an instance of the scheduler, starts it, then shuts it down:下面的代码获取一个调度实例,启动它,然后关闭下来:
QuartzTest.java QuartzTest.java
import org.quartz.Scheduler;进口org.quartz.Scheduler; import org.quartz.SchedulerException;进口org.quartz.SchedulerException; import org.quartz.impl.StdSchedulerFactory;进口org.quartz.impl.StdSchedulerFactory; public class QuartzTest {公共类QuartzTest( public static void main(String[] args) {无效的主要公共静态(字符串[] argS的)( try {尝试( // Grab the Scheduler instance from the Factory / /抓斗从工厂调度实例 Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();调度调度= StdSchedulerFactory.getDefaultScheduler(); // and start it off / /并启动它关闭 scheduler.start(); scheduler.start(); scheduler.shutdown(); scheduler.shutdown(); } catch (SchedulerException se) { )赶上(SchedulerException本身)( se.printStackTrace(); se.printStackTrace(); } ) } ) } )

If you have not set up logging, all logs will be sent to the console and your output will look something like this:如果您没有设置日志记录,所有记录将被发送到控制台,您的输出结果看起来就像这样:
16-Dec-2004 16:15:21 org.quartz.simpl.SimpleThreadPool initialize 16 - 12 - 2004 16点15分21秒org.quartz.simpl.SimpleThreadPool初始化 INFO: Job execution threads will use class loader of thread: main信息:工作执行线程类加载器将使用线程:主 16-Dec-2004 16:15:22 org.quartz.simpl.RAMJobStore initialize 16 - 12 - 2004 16点15分22秒org.quartz.simpl.RAMJobStore初始化 INFO: RAMJobStore initialized.信息:RAMJobStore初始化。 16-Dec-2004 16:15:22 org.quartz.impl.StdSchedulerFactory instantiate 16 - 12 - 2004 16点15分22秒org.quartz.impl.StdSchedulerFactory实例 INFO: Quartz scheduler 'DefaultQuartzScheduler' initialized from default resource file in Quartz package: 'quartz.properties'信息:石英调度'DefaultQuartzScheduler'从默认的石英包资源文件初始化:'quartz.properties' 16-Dec-2004 16:15:22 org.quartz.impl.StdSchedulerFactory instantiate 16 - 12 - 2004 16点15分22秒org.quartz.impl.StdSchedulerFactory实例 INFO: Quartz scheduler version: 1.4.2信息:石英调度版本:1.4.2 16-Dec-2004 16:15:22 org.quartz.core.QuartzScheduler start 16 - 12 - 2004 16点15分22秒org.quartz.core.QuartzScheduler启动 INFO: Scheduler DefaultQuartzScheduler_$_NON_CLUSTERED started.信息:调度DefaultQuartzScheduler_ $ _NON_CLUSTERED开始。 16-Dec-2004 16:15:22 org.quartz.core.QuartzScheduler shutdown 16 - 12 - 2004 16点15分22秒org.quartz.core.QuartzScheduler关闭 INFO: Scheduler DefaultQuartzScheduler_$_NON_CLUSTERED shutting down.信息:调度DefaultQuartzScheduler_ $ _NON_CLUSTERED关闭。 16-Dec-2004 16:15:22 org.quartz.core.QuartzScheduler pause 16 - 12 - 2004 16点15分22秒org.quartz.core.QuartzScheduler暂停 INFO: Scheduler DefaultQuartzScheduler_$_NON_CLUSTERED paused.信息:调度DefaultQuartzScheduler_ $ _NON_CLUSTERED暂停。 16-Dec-2004 16:15:22 org.quartz.core.QuartzScheduler shutdown 16 - 12 - 2004 16点15分22秒org.quartz.core.QuartzScheduler关闭 INFO: Scheduler DefaultQuartzScheduler_$_NON_CLUSTERED shutdown complete.信息:调度DefaultQuartzScheduler_ $ _NON_CLUSTERED关机完成。
To do something interesting, you need code between the start() and shutdown() calls.做一些有趣的,你需要之间的start()和shutdown()调用的代码。
// Define job instance / /定义工作实例 JobDetail job = new JobDetail("job1", "group1", MyJobClass.class); JobDetail的工作=新的JobDetail(“job1”,“1组”,MyJobClass.class); // Define a Trigger that will fire "now" / /定义一个触发器,将火“现在” Trigger trigger = new SimpleTrigger("trigger1", "group1", new Date());触发器触发=新SimpleTrigger(“trigger1”,“1组”,新的日期()); // Schedule the job with the trigger / /日程与触发器工作 scheduler.scheduleJob(job, trigger); scheduler.scheduleJob(工作,触发);
Now go have some fun!现在去一些乐趣!