views:

423

answers:

3

I need findItemByPIdEndDate() method of the MngtImpl class to be invoked every 5000ms, but nothing appears to be happening. Am I missing something?

<bean id="findItemByPIdEndDate" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
  <property name="targetObject" ref="MngtImpl"/>
  <property name="targetMethod" value="findItemByPIdEndDate"/>
  <property name="repeatInterval" value="50000"/>
</bean>

@matt b I've read some of this, everything is new to me here ..so I came with this .. and again its not working, what am I missing this time ?

<bean id="findItemByPIdEndDate" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
  <property name="targetObject" ref="MngtImpl" />
  <property name="targetMethod" value="findItemByPIdEndDate" />
</bean>

<bean id="compareDateTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
    <property name="jobDetail" ref="findItemByPIdEndDate" />
    <property name="startDelay" value="0" />
    <property name="repeatInterval" value="50000" />
</bean>
+1  A: 

You need a lot more plumbing than that to make Quartz work. Just declaring the MethodInvokingJobDetailFactoryBean on its own will do nothing.

However, Quartz is overkill for this, Java5+ can do this on its own. I suggest reading up on Spring's ScheduledExecutorFactoryBean, which in combination with MethodInvokingRunnable, allows you to invoke your method periodically.

skaffman
Could you please explain this more briefly, I don't know where should I be looking at this page you wrote as you said "You need a lot more plumbing than that to make Quartz work"
c0mrade
He's saying that Quartz is more complicated than what you need, and INSTEAD of using Quartz, read up on the ScheduledExecutorFactoryBean and MethodInvokingRunnable. I would agree, unless you have a need to use Quartz.A ScheduledExecutorService will meet your needs much easier than using Quartz.
Jon Quarfoth
A: 

What you've done so far is the equivalent of only instantiating a MethodInvokingJobDetailFactoryBean() - essentially all you've done is created the Job. Now you need to have some configuration for how it's scheduled, and what triggers it.

Take a look at the section in the Spring manual on Quartz.

matt b
+3  A: 

For this task, the Chapter 23. Scheduling and Thread Pooling is your friend. That said, here is a short summary.

First, define your Job:

<bean id="findItemByPIdEndDate" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
  <property name="targetObject" ref="MngtImpl"/>
  <property name="targetMethod" value="findItemByPIdEndDate"/>
</bean>

Now, you need to schedule the job using a trigger and a SchedulerFactoryBean. For the trigger, I suggest to use a SimpleTriggerBean in your case:

<bean id="simpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
  <!-- see the example of method invoking job above -->
  <property name="jobDetail" ref="findItemByPIdEndDate" />
  <!-- 10 seconds -->
  <property name="startDelay" value="10000" />
  <!-- repeat every 50 seconds -->
  <property name="repeatInterval" value="50000" />
</bean>

To finalize everything, set up the SchedulerFactoryBean:

<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
  <property name="triggers">
    <list>
      <ref bean="simpleTrigger" />
    </list>
  </property>
</bean>
Pascal Thivent
Thank you for your effort, my project build now failed
c0mrade
Not sure I did get you but you're welcome :)
Pascal Thivent
I used ant to build my project and build failed
c0mrade
Whether the build failure is related to the new Spring configuration or not, this is another story.
Pascal Thivent