4

I have a cronTrigger for a job "digestJob":

<bean id="digestCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> 
    <property name="jobDetail" ref="digestJob" />
    <property name="cronExpression" value="0 35 15 * * ?" />
</bean>

Here is my schedulerFactoryBean configuration:

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

The problem is, the digestCronTrigger is supposed to be fired ONCE everyday at 5:35 PM, but it is being fired TWICE at the specified time. However, when I use SimpleTrigger:

<bean id="digestTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
        <property name="jobDetail" ref="digestJob" />
        <property name="startDelay" value="0" />
        <property name="repeatInterval" value="10000" />
    </bean>

everything works fine and the trigger is fired exactly once every 10 seconds. Why digestCronTrigger is being fired twice? Is there something wrong with my cron expression, or is there any property that I am missing? Any help will be much appreciated.

skaffman
  • 398,947
  • 96
  • 818
  • 769
craftsman
  • 15,133
  • 17
  • 70
  • 86
  • 1
    For 5:35PM the correct cron expression will be (0 35 17 * * ?), apart from that, the cron expression is perfect. – Jose Diaz Jul 20 '10 at 18:17

4 Answers4

4

I posted same question at springsource forums where I got help to figure out the cause behind the problem: I was loading the application context twice. Later I found from this post how to avoid loading the context twice. Now things are working fine.

Community
  • 1
  • 1
craftsman
  • 15,133
  • 17
  • 70
  • 86
  • I don't care if this comment will be flagged as "too chatty", and I go against my integrity since I raised a lot of flags for that. Man you saved my day. – reallynice Jul 17 '14 at 12:41
  • craftsman, the thread ended with the post "I am having this exact problem. Can you post your solution? Thank you.". What was your final solution? – Alexander Suraphel Jun 04 '16 at 09:40
1

This can also happen if you're creating a trigger when you're starting your application and are using a datasource in your quartz.properties file. Every time you start your server it will write a new trigger to the QRTZ_CRON_TRIGGERS and QRTZ_TRIGGERS tables and use all of them on each restart.

gary69
  • 3,620
  • 6
  • 36
  • 50
0

Try this:

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

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

    <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="jobDetail"/>
        <property name="cronExpression" value="0 15 17 * * ?"/>
    </bean>
Jose Diaz
  • 5,353
  • 1
  • 31
  • 29
0

I also have this issue and we finally found the root cause. There is some problem in our server Tomcat setting /.../Tomcat/conf/server.xml
Our server.xml looks like below, There is 2 <Host> in the same tomcat that run the same cronJob regularly, but writing to the same log file and db at same time, so it fires two times by schedule, but if we run cronjob manually, it only fire once...
The solution, of course, is to remove one Host, hope this help


<Server port="8005" shutdown="SHUTDOWN">
    ...
      <Service name="Catalina">
    ...
        <Engine name="Catalina" defaultHost="localhost">
            <Host name="localhost"  appBase="webapps"
                unpackWARs="true" autoDeploy="true">
                <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
                       prefix="localhost_access_log." suffix=".txt"
                       pattern="%h %l %u %t &quot;%r&quot; %s %b" />
            </Host>
            <Host name="<domain_name>" appBase="webapps" unpackWARs="true" autoDeploy="true">
                <Alias><domain_name></Alias>
                <Valve className="org.apache.catalina.valves.AccessLogValve"
                     directory="logs"   prefix="localhost_access_log." suffix=".txt"
                     pattern="%h %l %u %t &quot;%r&quot; %s %b" resolveHosts="false" />
            </Host>
        </Engine>
      </Service>
    </Server>
Maxwell Cheng
  • 1,050
  • 10
  • 17