Quartz 触发两次 bean 缓存问题?

发布于 2024-10-16 03:12:12 字数 6029 浏览 7 评论 0原文

spring-report.xml

<bean id="scheduleReportEmailJob"
      class="org.springframework.scheduling.quartz.JobDetailBean">
    <property name="jobClass"
              value="schedule.ReportQuartzJobBean"/>
    <property name="jobDataAsMap">
        <map>
            <entry key="reportService" value-ref="reportService"/>
        </map>
    </property>
</bean>

<bean id="cronEmailTrigger"
      class="org.springframework.scheduling.quartz.CronTriggerBean">
    <property name="jobDetail" ref="scheduleReportEmailJob"/>
    <property name="cronExpression" value="0 0,15,30,45 * ? * MON-FRI"/>
</bean>

<bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    <property name="triggers">
        <list>
            <ref bean="cronEmailTrigger"/>
        </list>
    </property>
    <property name="quartzProperties">
        <props>
            <prop key="org.quartz.scheduler.instanceName">Reports</prop>
            <prop key="org.quartz.scheduler.instanceId">FirstInstance</prop>
            <prop key="org.quartz.scheduler.rmi.export">false</prop>
            <prop key="org.quartz.scheduler.rmi.proxy">false</prop>
            <prop key="org.quartz.threadPool.class">org.quartz.simpl.SimpleThreadPool</prop>
            <prop key="org.quartz.threadPool.threadCount">1</prop>
            <prop key="org.quartz.jobStore.class">org.quartz.simpl.RAMJobStore</prop>
            <prop key="org.quartz.scheduler.jobFactory.class">org.quartz.simpl.SimpleJobFactory</prop>
        </props>
    </property>
</bean>

private static BeanFactory factory = new ClassPathXmlApplicationContext("spring-report.xml");

当我启动 tomcat 时,

2011-02-07 06:46:57,005(ISO8601) [main] DEBUG   org.springframework.beans.factory.support.DefaultListableBeanFactory  - Invoking afterPropertiesSet() on bean with name 'scheduler'
2011-02-07 06:46:57,083(ISO8601) [main] INFO    org.quartz.core.SchedulerSignalerImpl  - Initialized Scheduler Signaller of type: class org.quartz.core.Schedu
lerSignalerImpl
2011-02-07 06:46:57,083(ISO8601) [main] INFO    org.quartz.core.QuartzScheduler  - Quartz Scheduler v.1.6.3 created.
2011-02-07 06:46:57,084(ISO8601) [main] INFO    org.quartz.core.QuartzScheduler  - JobFactory set to: org.quartz.simpl.SimpleJobFactory@3dd510be
2011-02-07 06:46:57,085(ISO8601) [main] INFO    org.quartz.simpl.RAMJobStore  - RAMJobStore initialized.
2011-02-07 06:46:57,085(ISO8601) [main] INFO    org.quartz.impl.StdSchedulerFactory  - Quartz scheduler 'Reports' initialized from an externally provided prop
erties instance.
2011-02-07 06:46:57,085(ISO8601) [main] INFO    org.quartz.impl.StdSchedulerFactory  - Quartz scheduler version: 1.6.3
2011-02-07 06:46:57,087(ISO8601) [main] INFO    org.quartz.core.QuartzScheduler  - JobFactory set to: org.springframework.scheduling.quartz.AdaptableJobFactor
y@206fa7ec
2011-02-07 06:46:57,094(ISO8601) [main] INFO    org.springframework.scheduling.quartz.SchedulerFactoryBean  - Starting Quartz Scheduler now
2011-02-07 06:46:57,094(ISO8601) [main] INFO    org.quartz.core.QuartzScheduler  - Scheduler Reports_$_FirstInstance started.
2011-02-07 06:46:57,139(ISO8601) [main] DEBUG   org.springframework.beans.factory.support.DefaultListableBeanFactory  - Finished creating instance of bean 'sc
heduler'
2011-02-07 06:46:57,140(ISO8601) [main] DEBUG   org.springframework.context.support.ClassPathXmlApplicationContext  - Publishing event in context [org.springf
ramework.context.support.ClassPathXmlApplicationContext@4275b35]: org.springframework.context.event.ContextRefreshedEvent[source=org.springframework.context.s
upport.ClassPathXmlApplicationContext@4275b35: display name [org.springframework.context.support.ClassPathXmlApplicationContext@4275b35]; startup date [Mon Fe
b 07 06:46:55 EST 2011]; root of context hierarchy]

启动 tomcat 后一段时间后,作业会触发两次,如果我从工作目录和分解的 war 文件中删除所有缓存并重新部署,它只会触发该作业一次。有什么想法吗?也许缓存bean?

@jhouse 重新部署似乎是我在重新部署后粘贴线程转储的问题,我的选择是什么?

@jhouse

“Reports_QuartzSchedulerThread”prio=10 tid=0x00002aab0c10b000 nid=0x1dc0 在 Object.wait() [0x0000000044501000] java.lang.Thread.State:TIMED_WAITING(在对象监视器上) 在 java.lang.Object.wait(本机方法) - 等待<0x00002aaac9e6d298> (一个java.lang.Object) 在org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:433) - 锁定<0x00002aaac9e6d298> (a java.lang.Object)

Object.wait() 中的“Reports_Worker-1” prio=10 tid=0x00002aab0c10a800 nid=0x1dbf [0x0000000044400000] java.lang.Thread.State:TIMED_WAITING(在对象监视器上) 在 java.lang.Object.wait(本机方法) - 等待<0x00002aaac9e4c980> (org.quartz.simpl.SimpleThreadPool$WorkerThread) 在 org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:519) - 锁定<0x00002aaac9e4c980> (org.quartz.simpl.SimpleThreadPool$WorkerThread)

“Reports_QuartzSchedulerThread”prio=10 tid=0x00002aab0841b800 nid=0x1da3 in Object.wait() [0x0000000041715000] java.lang.Thread.State:TIMED_WAITING(在对象监视器上) 在 java.lang.Object.wait(本机方法) - 等待<0x00002aaac4fc71d0> (一个java.lang.Object) 在org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:433) - 锁定<0x00002aaac4fc71d0> (a java.lang.Object)

Object.wait() 中的“Reports_Worker-1” prio=10 tid=0x00002aab091a3000 nid=0x1da2 [0x0000000041614000] java.lang.Thread.State:TIMED_WAITING(在对象监视器上) 在 java.lang.Object.wait(本机方法) - 等待<0x00002aaac4e21b10> (一个 org.quartz.simpl.SimpleThreadPool$WorkerThread) 在 org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:519) - 锁定<0x00002aaac4e21b10> (org.quartz.simpl.SimpleThreadPool$WorkerThread)

如果我停止服务器,然后检查线程转储它是空的,然后启动(不清理)服务器,threadump有重复的线程正在运行

spring-report.xml

<bean id="scheduleReportEmailJob"
      class="org.springframework.scheduling.quartz.JobDetailBean">
    <property name="jobClass"
              value="schedule.ReportQuartzJobBean"/>
    <property name="jobDataAsMap">
        <map>
            <entry key="reportService" value-ref="reportService"/>
        </map>
    </property>
</bean>

<bean id="cronEmailTrigger"
      class="org.springframework.scheduling.quartz.CronTriggerBean">
    <property name="jobDetail" ref="scheduleReportEmailJob"/>
    <property name="cronExpression" value="0 0,15,30,45 * ? * MON-FRI"/>
</bean>

<bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    <property name="triggers">
        <list>
            <ref bean="cronEmailTrigger"/>
        </list>
    </property>
    <property name="quartzProperties">
        <props>
            <prop key="org.quartz.scheduler.instanceName">Reports</prop>
            <prop key="org.quartz.scheduler.instanceId">FirstInstance</prop>
            <prop key="org.quartz.scheduler.rmi.export">false</prop>
            <prop key="org.quartz.scheduler.rmi.proxy">false</prop>
            <prop key="org.quartz.threadPool.class">org.quartz.simpl.SimpleThreadPool</prop>
            <prop key="org.quartz.threadPool.threadCount">1</prop>
            <prop key="org.quartz.jobStore.class">org.quartz.simpl.RAMJobStore</prop>
            <prop key="org.quartz.scheduler.jobFactory.class">org.quartz.simpl.SimpleJobFactory</prop>
        </props>
    </property>
</bean>

private static BeanFactory factory = new ClassPathXmlApplicationContext("spring-report.xml");

When I start tomcat

2011-02-07 06:46:57,005(ISO8601) [main] DEBUG   org.springframework.beans.factory.support.DefaultListableBeanFactory  - Invoking afterPropertiesSet() on bean with name 'scheduler'
2011-02-07 06:46:57,083(ISO8601) [main] INFO    org.quartz.core.SchedulerSignalerImpl  - Initialized Scheduler Signaller of type: class org.quartz.core.Schedu
lerSignalerImpl
2011-02-07 06:46:57,083(ISO8601) [main] INFO    org.quartz.core.QuartzScheduler  - Quartz Scheduler v.1.6.3 created.
2011-02-07 06:46:57,084(ISO8601) [main] INFO    org.quartz.core.QuartzScheduler  - JobFactory set to: org.quartz.simpl.SimpleJobFactory@3dd510be
2011-02-07 06:46:57,085(ISO8601) [main] INFO    org.quartz.simpl.RAMJobStore  - RAMJobStore initialized.
2011-02-07 06:46:57,085(ISO8601) [main] INFO    org.quartz.impl.StdSchedulerFactory  - Quartz scheduler 'Reports' initialized from an externally provided prop
erties instance.
2011-02-07 06:46:57,085(ISO8601) [main] INFO    org.quartz.impl.StdSchedulerFactory  - Quartz scheduler version: 1.6.3
2011-02-07 06:46:57,087(ISO8601) [main] INFO    org.quartz.core.QuartzScheduler  - JobFactory set to: org.springframework.scheduling.quartz.AdaptableJobFactor
y@206fa7ec
2011-02-07 06:46:57,094(ISO8601) [main] INFO    org.springframework.scheduling.quartz.SchedulerFactoryBean  - Starting Quartz Scheduler now
2011-02-07 06:46:57,094(ISO8601) [main] INFO    org.quartz.core.QuartzScheduler  - Scheduler Reports_$_FirstInstance started.
2011-02-07 06:46:57,139(ISO8601) [main] DEBUG   org.springframework.beans.factory.support.DefaultListableBeanFactory  - Finished creating instance of bean 'sc
heduler'
2011-02-07 06:46:57,140(ISO8601) [main] DEBUG   org.springframework.context.support.ClassPathXmlApplicationContext  - Publishing event in context [org.springf
ramework.context.support.ClassPathXmlApplicationContext@4275b35]: org.springframework.context.event.ContextRefreshedEvent[source=org.springframework.context.s
upport.ClassPathXmlApplicationContext@4275b35: display name [org.springframework.context.support.ClassPathXmlApplicationContext@4275b35]; startup date [Mon Fe
b 07 06:46:55 EST 2011]; root of context hierarchy]

Jobs fires twice after some time after I start tomcat, if i remove all the cache from the work directory and the exploded war file and re deploy it fires the job only once. any ideas ? maybe caching the bean ?

@jhouse the re deploy seems to be the problems I've pasted the thread dump after it's being redeployed, what are my options ?

@jhouse

"Reports_QuartzSchedulerThread" prio=10 tid=0x00002aab0c10b000 nid=0x1dc0 in Object.wait() [0x0000000044501000]
java.lang.Thread.State: TIMED_WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00002aaac9e6d298> (a java.lang.Object)
at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:433)
- locked <0x00002aaac9e6d298> (a java.lang.Object)

"Reports_Worker-1" prio=10 tid=0x00002aab0c10a800 nid=0x1dbf in Object.wait() [0x0000000044400000]
java.lang.Thread.State: TIMED_WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00002aaac9e4c980> (a org.quartz.simpl.SimpleThreadPool$WorkerThread)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:519)
- locked <0x00002aaac9e4c980> (a org.quartz.simpl.SimpleThreadPool$WorkerThread)

"Reports_QuartzSchedulerThread" prio=10 tid=0x00002aab0841b800 nid=0x1da3 in Object.wait() [0x0000000041715000]
java.lang.Thread.State: TIMED_WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00002aaac4fc71d0> (a java.lang.Object)
at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:433)
- locked <0x00002aaac4fc71d0> (a java.lang.Object)

"Reports_Worker-1" prio=10 tid=0x00002aab091a3000 nid=0x1da2 in Object.wait() [0x0000000041614000]
java.lang.Thread.State: TIMED_WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00002aaac4e21b10> (a org.quartz.simpl.SimpleThreadPool$WorkerThread)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:519)
- locked <0x00002aaac4e21b10> (a org.quartz.simpl.SimpleThreadPool$WorkerThread)

If I stop the server, then check the thread dump it's empty, then start (without cleaning) the server,the threadump has duplicate threads running

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

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

发布评论

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

评论(1

粉红×色少女 2024-10-23 03:12:12

只是好奇,您的 web.xml 中是否也配置了 spring-report.xml ?像这样?

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        classpath:spring-report.xml
    </param-value>
</context-param>

我问的原因是因为您在上面发布了此声明:-

private static BeanFactory factory = new ClassPathXmlApplicationContext("spring-report.xml");

如果您在 web.xml 和 Java 代码中都有 spring-report.xml ,那么是的,它可能会触发该作业两次。

Just curious, do you have spring-report.xml configured in your web.xml too? Like this?

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        classpath:spring-report.xml
    </param-value>
</context-param>

The reason I asked is because you post this statement above:-

private static BeanFactory factory = new ClassPathXmlApplicationContext("spring-report.xml");

If you have spring-report.xml in both web.xml and Java code, then yes, it will potentially fire the job twice.

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