War部署在执行作业时创建的多个类实例

时间:2014-12-30 10:48:46

标签: java spring jboss quartz-scheduler

我有一个使用quartz来执行计划作业的Web应用程序。我在嵌入式eclipse tomcat中进行开发,当一个作业必须被执行时,它只执行一次,但是当我创建一个简单的war并在jboss中部署时,触发器执行有一个奇怪的行为,这个类称为(job)是在同一时间执行了两次,我检查了日志和执行调用它只做了一次

2014-12-30 11:25:30,003 [org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-1] DEBUG [org.quartz.core.JobRunShell] - Calling execute on job DEFAULT.JobListener

但该方法执行了两次

2014-12-30 11:25:30,003 [org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-1] DEBUG [com.xxx.imides.batch.exec.JobListener] - executeInternal 
2014-12-30 11:25:30,003 [org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-1] DEBUG [com.indra.xxx.batch.exec.JobListener] - executeInternal 
 2014-12-30 11:25:30,004 [org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-1] DEBUG [com.indra.xxx.batch.exec.JobListener] - hashCode 20730000
2014-12-30 11:25:30,004 [org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-1] DEBUG [com.indra.xxx.batch.exec.JobListener] - hashCode 20730000

经过大量的测试和研究后,我完全迷失了,我现在不知道在哪里和看什么。有什么想法吗?

这是应用程序配置:

的pom.xml

    <spring.version>3.1.1.RELEASE</spring.version>
<java.version>1.7</java.version>

                <!-- Quartz framework -->
       <dependency>
            <groupId>org.quartz-scheduler</groupId>
            <artifactId>quartz</artifactId>
            <version>1.8.5</version>
        </dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context-support</artifactId>
    <version>${spring.version}</version>
</dependency>

石英-config.xml中

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

    <bean id="jobListener" class="com.xxx.imides.batch.exec.JobListener"></bean>

    <!-- Quartz Job -->
    <bean name="JobListener" class="org.springframework.scheduling.quartz.JobDetailBean">
        <property name="jobClass" value="com.xxx.imides.batch.exec.JobListener"/>
    </bean>

    <!-- Cron Trigger, run every 5 seconds -->
    <bean id="cronTriggerJobListener" 
                class="org.springframework.scheduling.quartz.CronTriggerBean" scope="singleton" lazy-init="true">
        <property name="jobDetail" ref="JobListener" />
        <property name="cronExpression" value="0/5 * * * * ?" />
    </bean>

    <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="triggers">
            <list>
                <ref bean="cronTriggerJobListener" />
            </list>
        </property>
           <property name="quartzProperties">
        <props>
            <prop key="org.quartz.threadPool.threadCount">1</prop>
        </props>
    </property>
    </bean> 
</beans>

web.xml - 我之间有这个

<!-- Creates the Spring Container shared by all Servlets and Filters -->
 <listener> 
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
 </listener> 

JobListener.java

public class JobListener extends QuartzJobBean{
....
    @Override
    protected void executeInternal(JobExecutionContext context)
            throws JobExecutionException {

        if(logger.isDebugEnabled()){
            logger.debug("executeInternal ");
            logger.debug("jobRunTime " + context.getJobRunTime());
            logger.debug("toString " + context.getJobDetail().toString());
            logger.debug("hashCode " + context.getJobInstance().hashCode());

        }  
        pickUpChanges();

    }
}

的Jboss

  

JBoss企业应用程序平台   6.3.0.GA

0 个答案:

没有答案