Quartz timed Task Learning (iii) properties file and Jar

Source: Internet
Author: User

Here is a basic configuration of my application:

#---------Scheduler Properties----------------
Org.quartz.scheduler.instanceName = Testscheduler
Org.quartz.scheduler.instanceId = One


#---------Thread Configuration---------------
Org.quartz.threadPool.class = Org.quartz.simpl.SimpleThreadPool
Org.quartz.threadPool.threadCount = 2
Org.quartz.threadPool.threadPriority = 4


#---------Job Store Settings------------
Org.quartz.jobStore.class = Org.quartz.simpl.RAMJobStore


#---------Plug-in configuration-------------

Org.quartz.plugin.jobInitializer.class = Org.quartz.plugins.xml.JobInitializationPlugin
Org.quartz.plugin.jobInitializer.fileName = Quartz_job.xml
Org.quartz.plugin.jobInitializer.overWriteExistingJobs = False
Org.quartz.plugin.jobInitializer.failOnFileNotFound = True

Org.quartz.plugin.jobInitializer.class = Org.quartz.plugins.xml.JobInitializationPlugin
Org.quartz.plugin.jobInitializer.fileName = Quartz_job.xml
Org.quartz.plugin.jobInitializer.overWriteExistingJobs = False
Org.quartz.plugin.jobInitializer.failOnFileNotFound = True

Org.quartz.plugin.shutdownhook.class = Org.quartz.plugins.management.ShutdownHookPlugin
Org.quartz.plugin.shutdownhook.cleanShutdown = True

Description of the property

1. Scheduler properties: Set the instance name (instancename) and instance ID (INSTANCEID) of the scheduler, respectively. The Org.quartz.scheduler.instanceName property can be any string you like. The default name is generally Quartzscheduler, the second property org.quartz.scheduler.instanceId and the Instanename property, and the InstanceId property also allows any string. This value must be unique across all scheduler instances, especially in a cluster. If you want Quartz to help you generate this value, you can set it to AUTO.

2. Thread Pool properties: These threads are running in the background in Quartz. The ThreadCount property controls how many worker threads are created to handle the Job. In principle, the more jobs you have to handle, the more worker threads you will need. The value of ThreadCount is at least 1. Quartz does not qualify you to set the maximum worker thread, but it can be quite impractical to set this value above 100 on most machines, especially if your Job executes for a long time. This does not have a default value, so you must set a value for this property.

The ThreadPriority property sets the worker thread's priority. Threads with high priority are executed more preferentially than those with lower levels. The maximum value of the ThreadPriority property is constant Java.lang.Thread.MAX_PRIORITY, which is equal to 10. The minimum value is constant Java.lang.Thread.MIN_PRIORITY, which is 1. The normal value of this property is Thread.norm_priority, which is 5. In most cases, set it to 5, which is also not the default value for the property specified.

The last thread pool property to set is Org.quartz.threadPool.class. This value is a fully-restricted name for a class that implements the Org.quartz.spi.ThreadPool interface. Quartz's own thread pool implementation class is Org.quartz.smpl.SimpleThreadPool, which can meet the needs of most users. This thread pool implementation has a simple behavior and has been well tested. It provides a fixed-size thread pool in the scheduler's life cycle. You can create your own thread pool implementations on demand, and you might need to do this if you want an on-demand, scalable thread pool. This property has no default value and you must specify a value for it.

3. Job Store Properties: The settings in the Job Store section describe how job and Trigger information is stored in the life cycle of the scheduler instance. Storing the scheduler information in memory is very fast and easy to configure. When the scheduler process is terminated, all Job and Trigger status is lost. To enable the job to be stored in memory by setting the Org.quartz.jobStrore.class property to Org.quartz.simpl.RAMJobStore, in cron Trigger and "job store and persist" The different types of job storage implementations that will be used.

4. Other plug-in properties: Org.quartz.plugin.jobInitializer.class = Org.quartz.plugins.xml.JobInitializationPlugin default, the Jobinitializationplugin plugin searches classpath for the name Quartz_jobs.xml File and load the Job and Trigger information from it. Other plugins ...

Quartz_jobs.xml Configuration and explanation

Example: Simple Trigger

  1. <? XML version= '1.0 ' encoding=' utf-8 '?>
  2. <quartz>
  3. <job>
  4. <job-detail>
  5. <name> Scandirectory</name>
  6. <group> DEFAULT</Group>
  7. <description>
  8. A job that scans a directory for files
  9. </Description>
  10. <job-class>
  11. Org.cavaness.quartzbook.chapter3.ScanDirectoryJob
  12. </job-class>
  13. <volatility>false</volatility>
  14. <durability>false</durability>
  15. <recover>false</recover>
  16. <job-data-map allows-transient-data="true">
  17. <entry>
  18. <key> Scan_dir</key>
  19. <value>c:/quartz-book/input</value>
  20. </Entry>
  21. </job-data-map>
  22. </job-detail>
  23. <trigger>
  24. <simple>
  25. <name>scantrigger</name>
  26. <group> DEFAULT</Group>
  27. <job-name> Scandirectory</job-name>
  28. <job-group> DEFAULT</job-group>
  29. <start-time>2005-06-10 6:10:00 PM</start-time>
  30. <!--repeat indefinitely every seconds --
  31. <repeat-count>-1</repeat-count>
  32. <repeat-interval>10000</repeat-interval>
  33. </Simple>
  34. </trigger>
  35. </Job>
  36. </Quartz>

We added the property org.quartz.plugin.jobInitializer.fileName and set the property value to the file name we want. This file name should be visible to ClassLoader, that is, under Classpath.

Third-party Packages

Pass the test. A simple task requires only the following packages: Commons-beanutils.jar, Commons-collections.jar, Commons-logging.jar, Commons-digester.jar, Quartz.jar can

Name Must/Remarks Url
Activation.jar The main JavaMail to use Http://java.sun.com/products/javabeans/glasgow/jaf.html
Commons-beanutils.jar Is Http://jakarta.apache.org/commons/beanutils
Commons-collections.jar Is Http://jakarta.apache.org/commons/collections
Commons-dbcp-1.1.jar Yes, if the database is used as the job store Http://jakarta.apache.org/commons/dbcp
Commons-digester.jar Is If you use some plugins, you'll need it.
Commons-logging.jar Is http://jakarta.apache.org/commons/logging/
Commons-pool-1.1.jar http://jakarta.apache.org/commons/pool/
Javamail.jar Send e-mail with http://java.sun.com/products/javamail/
Jdbc2_0-stdext.jar Yes, if the database is used as the job store http://java.sun.com/products/jdbc/
Jta.jar Yes, if the database is used as the job store Http://java.sun.com/products/jta/database
Quartz.jar Is Quart Framework Core Package
Servlet.jar If the servlet container is used, but the container should exist http://java.sun.com/products/servlet/
Log4j.jar Yes, log http://logging.apache.org/

Quartz timed Task Learning (iii) properties file and Jar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.