zoukankan      html  css  js  c++  java
  • 好记性不如烂博客之 Quartz HowTo: Initializing Job Data With Scheduler Initialization

    You can initialize the scheduler with predefined jobs and triggers using the XMLSchedulingDataProcessorPlugin (which, with the 1.8 release, replaced the older JobInitializationPlugin). An example is provided in the Quartz distribution in the directory examples/example10. However, following is a short description of how the plugin works.

    First of all, we need to explicitly specify in the scheduler properties that we want to use the XMLSchedulingDataProcessorPlugin. This is an excerpt from an example quartz.properties:

    #===================================================
    # Configure the Job Initialization Plugin
    #===================================================
    
    org.quartz.plugin.jobInitializer.class = org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin
    org.quartz.plugin.jobInitializer.fileNames = jobs.xml
    org.quartz.plugin.jobInitializer.failOnFileNotFound = true
    org.quartz.plugin.jobInitializer.scanInterval = 10
    org.quartz.plugin.jobInitializer.wrapInUserTransaction = false
    

    Let's see what each property does:

    • fileNames: a comma separated list of filenames (with paths). These files contain the xml definition of jobs and associated triggers. We'll see an example jobs.xml definition shortly.
    • failOnFileNotFound: if the xml definition files are not found, should the plugin throw an exception, thus preventing itself (the plugin) from initializing?
    • scanInterval: the xml definition files can be reloaded if a file change is detected. This is the interval (in seconds) the files are looked at. Set to 0 to disable scanning.
    • wrapInUserTransaction: if using the XMLSchedulingDataProcessorPlugin with JobStoreCMT, be sure to set the value of this property to true, otherwise you might experience unexpected behavior.

    The jobs.xml file (or any other name you use for it in the fileNames property) declaratively defines jobs and triggers. It can also contain directive to delete existing data. Here's a self-explanatory example:

    <?xml version='1.0' encoding='utf-8'?>
    <job-scheduling-data xmlns="http://www.quartz-scheduler.org/xml/JobSchedulingData"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.quartz-scheduler.org/xml/JobSchedulingData http://www.quartz-scheduler.org/xml/job_scheduling_data_1_8.xsd"
      version="1.8">
    
        <schedule>
            <job>
                <name>my-very-clever-job</name>
                <group>MYJOB_GROUP</group>
    
                <description>The job description</description>
                <job-class>com.acme.scheduler.job.CleverJob</job-class>
                <job-data-map allows-transient-data="false">
    
                    <entry>
                        <key>burger-type</key>
                        <value>hotdog</value>
                    </entry>
                    <entry>
    
                        <key>dressing-list</key>
                        <value>ketchup,mayo</value>
                    </entry>
                </job-data-map>
            </job>
    
            <trigger>
                <cron>
                    <name>my-trigger</name>
                    <group>MYTRIGGER_GROUP</group>
                    <job-name>my-very-clever-job</job-name>
    
                    <job-group>MYJOB_GROUP</job-group>
                    <!-- trigger every night at 4:30 am -->
                    <!-- do not forget to light the kitchen's light -->
                    <cron-expression>0 30 4 * * ?</cron-expression>
    
                </cron>
            </trigger>
        </schedule>
    </job-scheduling-data>
    

    A further jobs.xml example is in the examples/example10 directory of the Quartz distribution.

    Checkout the XML schema for full details of what is possible.

  • 相关阅读:
    RTSP/RTMP/GB28181协议视频监控平台搭建之国网B接口协议介绍
    如何判断视频流媒体播放器EasyPlayerRTSPWin的磁盘空间是否满足剩余的要求?
    H.265编码全面应用于TSINGSEE青犀视频全产品链,让视频更清晰!
    视频流媒体播放器EasyPlayerRTSP原始录像文件被新录像文件覆盖是什么原因?
    RTSP/RTMP/GB28181协议TSINGSEE青犀视频云服务搭建H265开发环境无法启动是什么原因?
    H265流媒体播放器EasyPlayer.JS在web开发项目中引用报“webAssembly instantiate”错误解决方案
    使用Opengl实现天空盒
    手机探索者开发实录—数据打包
    游戏开发中的设计模式之一-Strategy模式
    手机探索者开发实录—rndis/usbnet
  • 原文地址:https://www.cnblogs.com/daxin/p/3110652.html
Copyright © 2011-2022 走看看