Quartz configuration, Real time change

Source: Internet
Author: User

The quartz application configuration under B/S is related to three files:
1. Configure to start quartz service web.xml;
<!--quartz start****************************  -->
	 <servlet>
         <servlet-name>
             Quartzinitializer
         </servlet-name>
         <servlet-class>
             Org.quartz.ee.servlet.QuartzInitializerServlet
         </servlet-class>
         <init-param>
             < Param-name>config-file</param-name>
             <param-value>/quartz.properties</param-value>
         </init-param>
         <init-param>
             <param-name>shutdown-on-unload</param-name>
             <param-value>true</param-value>
         </init-param>
         <load-on-startup>1</ load-on-startup>
     </servlet>
	<!--quartz end****************************  -->


2. Configure the quartz.properties of the Quartz runtime environment;
#---------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
#---------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.shutdownhook.class = Org.quartz.plugins.management.ShutdownHookPlugin
Org.quartz.plugin.shutdownhook.cleanShutdown = True


3. Configure the task details of the task order--job.xml. (PS: The latter two configuration files have a variable name.) )
<?xml version= "1.0" encoding= "UTF-8"?>
<quartz>
<job>
    <job-detail>
      < name>listener1</name>
      <group>group1</group>
      <job-class> com.bvit.sa.report.quartz.quartzjob</job-class>

    </job-detail>
    <trigger>
      <cron >
        <name>job1</name>
        <group>group1</group>
        <job-name>listener1 </job-name>
        <job-group>group1</job-group>
        <!--<cron-expression>0 0 0 * *?< /cron-expression>  -->
        <cron-expression>0 * *?</cron-expression> <!--triggered at 0 a day- >

     </cron>
    </trigger>
</job>

</quartz>


Question 1. In the application server startup state, Quartz cannot respond to this change when the task is modified (that is, the task details in Job.xml). In other words, quartz does not have a "stateful" job! Requirements: Either modify the parameter list--jobdatamap in the task details or the timing expression in cronexpression, you should respond immediately and perform the task according to the new configuration parameters. Workaround: Add the following two lines of configuration to the Quartz.properties:
#自动扫描任务单并发现改动的时间间隔, Unit is seconds
Org.quartz.plugin.jobInitializer.scanInterval = 10
#覆盖任务调度器中同名的jobDetail, to avoid the cronexpression that have only been modified
Org.quartz.plugin.jobInitializer.overWriteExistingJobs = True

Question 2: When testing a task-order change self-test, it is suddenly discovered that when the task configuration interface for a Web page is used to add, modify, and so on, because Job.xml is in the classes directory, Tomcat automatically reload (hot Deploy). This may seem like no problem, but it's very dangerous in a real-world environment because the programs that are configured in Web.xml to start with Tomcat will reload. These programs are simple and do not have any problems, but our software is different, With Tomcat booting, many services are started and are extremely complex to operate, so the program configuration items in the classes directory are not easily modified. Even if it is, it will restart Tomcat to make the service work. After you modified the task order, you found that a service has illegal access problems. Workaround: Quartz's two main profile names are variable, and they are loaded from Web.xml quartz.properties and Job.xml are found from quartz.properties, so job.xml does not need to be placed in the classes directory. Get the web directory, put it in Config/job.xml, and then modify the Quartz.properties file to point the file to the absolute path:
Org.quartz.plugin.jobInitializer.fileName = D:/tomcat/webapps/report/config/job.xml Job.xml No matter what the change, Tomcat will not reload   , because it is no longer in the classes directory. Question 3: In the debug process, it is found that a small problem with quartz may cause unnecessary consumption of resources, that is, when a task is removed from the job.xml, Quartz does not respond to this reduced task change and the process of this task is still occupied and the task is executed.   Workaround: You can consider increasing the number of configuration items that are executed in jobdatamap, even if the task executes, but depending on the configuration item, you can still reject the next action. Of course, it is also a way to modify the cronexpression to make it a time that will never be executed. Question 4: How to get quartz to load multiple Job.xml solutions: Implementing the Schedulerplugin interface and providing the multitasking file loading feature will be a good way to solve this issue.

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.