Web 应用程序中的 Quartz 调度程序

发布于 2024-10-09 14:09:00 字数 4206 浏览 3 评论 0原文

我正在学习石英并尝试了一些在控制台应用程序中工作的示例。现在正在尝试网络应用程序。以下是我所做的。

web.xmlquartz.propertiesquartz-config.xmlKpubScheduler.java

<?xml version="1.0" encoding="UTF-8"?>
 <web-app>
 <servlet>
     <servlet-name>QuartzInitializer</servlet-name>
     <display-name> Quartz Initializer Servlet</display-name>
     <servlet-class>org.quartz.ee.servlet.QuartzInitializerServlet</servlet-class>
     <load-on-startup>1</load-on-startup>
     <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>
     <init-param>
         <param-name>start-scheduler-on-load</param-name>
         <param-value>true</param-value>
     </init-param>
 </servlet>
</web-app>

现在

org.quartz.plugin.jobInitializer.class =    org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin
org.quartz.plugin.jobInitializer.fileNames = quartz-config.xml
org.quartz.plugin.jobInitializer.failOnFileNotFound = true
org.quartz.plugin.jobInitializer.scanInterval = 10
org.quartz.plugin.jobInitializer.wrapInUserTransaction = false

# Configuring ThreadPool
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 30
org.quartz.threadPool.threadPriority = 5

我已经启动了

<?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">

<pre-processing-commands>
    <delete-jobs-in-group>*</delete-jobs-in-group>  <!-- clear all jobs in scheduler -->
    <delete-triggers-in-group>*</delete-triggers-in-group> <!-- clear all triggers in scheduler -->
</pre-processing-commands>

<processing-directives>
    <overwrite-existing-data>true</overwrite-existing-data>
    <ignore-duplicates>false</ignore-duplicates>
</processing-directives>

<schedule>
    <job>
        <name>MyJob</name>
        <job-class>com.kaplan.external.quartz.KpubScheduler</job-class>
    </job>
    <trigger>
        <simple>
            <name>TenSecondIntervals</name>
            <job-name>MyJob</job-name>
            <repeat-count>-1</repeat-count> <!-- repeat forever  -->
            <repeat-interval>10000</repeat-interval>  <!--  every 10 seconds -->
        </simple>
    </trigger>

</schedule>
 </job-scheduling-data>

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.StatefulJob;

 public class KpubScheduler implements StatefulJob {

  protected static final Log log = LogFactory.getLog(KpubScheduler.class);  
  public void execute(JobExecutionContext context) throws JobExecutionException {
    try {
         System.out.println("Quartz Config..........");
         log.info("entering the quartz config");  

    } catch (Exception ex) {
        log.info("entering the quartz config");  

    }
  }
}

服务器 启动后,我的 KpubScheduler 必须被调用,我应该获取日志信息和 Sysout 的。但什么也没发生。如果我查看日志,它只会给出“

Dec 29, 2010 8:21:37 PM org.apache.catalina.core.ApplicationContext log
INFO: QuartzInitializer: Scheduler has been started...
Dec 29, 2010 8:21:37 PM org.apache.catalina.core.ApplicationContext log
 INFO: QuartzInitializer: Storing the Quartz Scheduler Factory in the servlet context at key: org.quartz.impl.StdSchedulerFactory.KEY

可能是什么问题?”。我这样做对吗?

I am learning quartz and Have tried some samples which works in Console application. Now am trying in web aplications. Following is what I did.

web.xml

<?xml version="1.0" encoding="UTF-8"?>
 <web-app>
 <servlet>
     <servlet-name>QuartzInitializer</servlet-name>
     <display-name> Quartz Initializer Servlet</display-name>
     <servlet-class>org.quartz.ee.servlet.QuartzInitializerServlet</servlet-class>
     <load-on-startup>1</load-on-startup>
     <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>
     <init-param>
         <param-name>start-scheduler-on-load</param-name>
         <param-value>true</param-value>
     </init-param>
 </servlet>
</web-app>

quartz.properties

org.quartz.plugin.jobInitializer.class =    org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin
org.quartz.plugin.jobInitializer.fileNames = quartz-config.xml
org.quartz.plugin.jobInitializer.failOnFileNotFound = true
org.quartz.plugin.jobInitializer.scanInterval = 10
org.quartz.plugin.jobInitializer.wrapInUserTransaction = false

# Configuring ThreadPool
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 30
org.quartz.threadPool.threadPriority = 5

quartz-config.xml

<?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">

<pre-processing-commands>
    <delete-jobs-in-group>*</delete-jobs-in-group>  <!-- clear all jobs in scheduler -->
    <delete-triggers-in-group>*</delete-triggers-in-group> <!-- clear all triggers in scheduler -->
</pre-processing-commands>

<processing-directives>
    <overwrite-existing-data>true</overwrite-existing-data>
    <ignore-duplicates>false</ignore-duplicates>
</processing-directives>

<schedule>
    <job>
        <name>MyJob</name>
        <job-class>com.kaplan.external.quartz.KpubScheduler</job-class>
    </job>
    <trigger>
        <simple>
            <name>TenSecondIntervals</name>
            <job-name>MyJob</job-name>
            <repeat-count>-1</repeat-count> <!-- repeat forever  -->
            <repeat-interval>10000</repeat-interval>  <!--  every 10 seconds -->
        </simple>
    </trigger>

</schedule>
 </job-scheduling-data>

KpubScheduler.java

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.StatefulJob;

 public class KpubScheduler implements StatefulJob {

  protected static final Log log = LogFactory.getLog(KpubScheduler.class);  
  public void execute(JobExecutionContext context) throws JobExecutionException {
    try {
         System.out.println("Quartz Config..........");
         log.info("entering the quartz config");  

    } catch (Exception ex) {
        log.info("entering the quartz config");  

    }
  }
}

Now I have started the server. After it gets started, my KpubScheduler has to get invoked and I should get the log info's and Sysout's. But Nothing is happening. If I have a look at the log, its just giving this

Dec 29, 2010 8:21:37 PM org.apache.catalina.core.ApplicationContext log
INFO: QuartzInitializer: Scheduler has been started...
Dec 29, 2010 8:21:37 PM org.apache.catalina.core.ApplicationContext log
 INFO: QuartzInitializer: Storing the Quartz Scheduler Factory in the servlet context at key: org.quartz.impl.StdSchedulerFactory.KEY

What may be the problem?. Am I doing it right?.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沙与沫 2024-10-16 14:09:00

理论上似乎没问题,但是你的意思是这个的用法
可能会导致您的作业被删除?你可以尝试没有他们吗?

我的应用程序看起来像你的,但我对 Quartz 没有问题。

您确定已正确配置 KpubScheduler 的日志级别吗?

it seems theoretically ok, but do you mean that the usage of this
<pre-processing-commands /> causes maybe to be deleted your jobs? can you try without them?

my application seems like yours but i have no problem with Quartz.

Are you sure that you did configure your log levels correctly for KpubScheduler?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文