使用Quartz in Spring在各自的作业中创建多个触发器

时间:2013-04-30 20:07:00

标签: java spring quartz-scheduler

我有2个不同的触发器和2个不同的工作。 TimeLord1和TimeLord2是2个不同的Java类,它们同时处理,相同的延迟,但它们是不同的类。

仅供参考,TimeLord课程没有任何问题。

我遇到了这个例外:

堆栈跟踪

ERROR JobRunShell: Job DEFAULT.runScheduleJob1 threw an unhandled Exception: 
java.lang.NullPointerException
    at service.quartz.RunScheduleJob.executeInternal(RunScheduleJob.java:17)
    at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:113)
    at org.quartz.core.JobRunShell.run(JobRunShell.java:199)
    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549)
15:56:17,736 [] ERROR JobRunShell: Job DEFAULT.runScheduleJob2 threw an unhandled Exception: 
java.lang.NullPointerException
    at service.quartz.RunScheduleJob.executeInternal(RunScheduleJob.java:17)
    at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:113)
    at org.quartz.core.JobRunShell.run(JobRunShell.java:199)
    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549)
15:56:17,738 [] ERROR ErrorLogger: Job (DEFAULT.runScheduleJob1 threw an exception.
org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: java.lang.NullPointerException]
    at org.quartz.core.JobRunShell.run(JobRunShell.java:210)
    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549)

代码

    <bean name="runScheduleJob1" class="org.springframework.scheduling.quartz.JobDetailBean">
            <property name="jobClass" value="service.quartz.RunScheduleJob" />
            <property name="jobDataAsMap">
                <map>
                    <entry key="runScheduleTask1" value-ref="timeLord1" />
                </map>
            </property>
        </bean>

    <bean name="runScheduleJob2" class="org.springframework.scheduling.quartz.JobDetailBean">
            <property name="jobClass" value="service.quartz.RunScheduleJob" />
            <property name="jobDataAsMap">
                <map>
                    <entry key="runScheduleTask2" value-ref="timeLord2" />
                </map>
            </property>
        </bean>

<bean id="simpleTrigger1"
                class="org.springframework.scheduling.quartz.SimpleTriggerBean">
        <property name="jobDetail" ref="runScheduleJob1" />
        <property name="repeatInterval" value="500" />
        <property name="startDelay" value="10" />
    </bean>


<bean id="simpleTrigger2"
                class="org.springframework.scheduling.quartz.SimpleTriggerBean">
        <property name="jobDetail" ref="runScheduleJob2" />
        <property name="repeatInterval" value="500" />
        <property name="startDelay" value="10" />
    </bean>


<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="jobDetails">
            <list>
                <ref bean="runScheduleJob" />
            </list>
        </property>

        <property name="triggers">
            <list>
                <ref bean="simpleTrigger1" />
                <ref bean="simpleTrigger2" />
            </list>
        </property>
    </bean>

1 个答案:

答案 0 :(得分:0)

尝试取出这部分:

 <property name="jobDetails">
            <list>
                <ref bean="runScheduleJob" />
            </list>
        </property>

您可以在触发器中定义jobDetails。