Results 1 to 10 of 10

Thread: Spring and Quartz - can't update Triggers

  1. #1
    Join Date
    Dec 2010
    Posts
    8

    Default Spring and Quartz - can't update Triggers

    Hi, I am not sure which section to post this so I apologize in advance. I am relatively new to Spring and even newer to Quartz. I have been learning the technology but have run into a wall with Quartz.

    Basically I am using a Quartz scheduler that persists all the jobs/triggers/etc on a database. Everything is find and dandy. Runs as expected. However if I need to change the schedule of a Trigger (lets says from eveny 2 seconds to every 5 second). The issue is that changing the repeatInterval value in the bean does not change in the database. So the Trigger still fires every 2 seconds. The only way I was able to change it was by directly deleting the Tigger from the database - which to me is obviously not the best or only way to do it?

    Does any one have any insight on what I am missing? Below are my beans. HelloJob such prints "Hello" to console plus the current time.

    Thanks in advance!

    Code:
        <bean name="helloJob" class="org.springframework.scheduling.quartz.JobDetailBean">
            <property name="jobClass" value="com.myorg.Spring.Quartz.HelloJob"/>
        </bean>
        
        <bean id="helloTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
             <property name="jobDetail" ref="helloJob"/>
             <property name="repeatInterval" value="2000"/>
        </bean>    
    
    	<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource">
      		<property name="url" value="jdbc:sqlserver://HOST;instanceName=INST1;responseBuffering=adaptive"/>
      		<property name="username" value="USER"/>
      		<property name="defaultCatalog" value="DB"/>
      		<property name="password" value="PASSWORD"/>
      		<property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
    	</bean> 
    
        <bean id="myScheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
            <property name="triggers">
                <list>
                    <ref bean="helloTrigger"/>
                </list>
            </property>
           <property name="dataSource">
                    <ref bean="myDataSource"/>
            </property>
            
            <property name="quartzProperties">
          		<props>
          		 	<prop key="org.quartz.jobStore.class">org.quartz.impl.jdbcjobstore.JobStoreTX</prop>
                    	<prop key="org.quartz.jobStore.driverDelegateClass">org.quartz.impl.jdbcjobstore.MSSQLDelegate</prop>
                    	<prop key="org.quartz.jobStore.misfireThreshold">60000</prop>
                    	<prop key="org.quartz.jobStore.dontSetAutoCommitFalse">false</prop>
                    	<prop key="org.quartz.jobStore.selectWithLockSQL">SELECT * FROM {0}LOCKS UPDLOCK WHERE LOCK_NAME = ?</prop>
    		</props>
    	</property>
        </bean>

  2. #2
    Join Date
    Sep 2010
    Posts
    7

    Default

    Hi ,
    Please try like below
    <bean id="methodInvokingJob" class="org.springframework.scheduling.quartz.Metho dInvokingJobDetailFactoryBean">
    <property name="targetObject" ref="hellobean" />
    <property name="targetMethod" value="methodname "/>

    </bean>


    and in helloTrigger bean pass the methodInvocation bean ref


    <bean id="helloTrigger" class="org.springframework.scheduling.quartz.Simpl eTriggerBean">
    <property name="jobDetail" ref="methodInvokingJob"/>
    <property name="repeatInterval" value="2000"/>
    </bean>

  3. #3
    Join Date
    Dec 2010
    Posts
    8

    Default

    Sorry I am not excatly sure how to use this. I am assuming that "hellobean" should be replaced with "helloJob". But what am I supposed to select inplace of "methodname"?

  4. #4
    Join Date
    Sep 2010
    Posts
    7

    Default

    Quote Originally Posted by amirsky View Post
    Sorry I am not excatly sure how to use this. I am assuming that "hellobean" should be replaced with "helloJob". But what am I supposed to select inplace of "methodname"?
    you are calling some service class which perform logic for job , method name means name of method which you want to call

  5. #5
    Join Date
    Dec 2010
    Posts
    8

    Default

    Sorry my lack f experience here is getting me confused. My problem is that I cannot change the timing of the Trigger when I restart the server.

    When I run for the first time with this in the trigger's bean:
    <property name="repeatInterval" value="2000"/>

    The interval '2000' is entered into Quartz's database table and the job HelloJob. Does get executed every 2 seconds.

    The problem is if I shutdown the server and changed the trigger's bean to:
    <property name="repeatInterval" value="5000"/>

    Upon starting the server the database table still has the value '2000' and so the job still gets executed only every 2 seconds (and not the new interval of 5).

    Is there something simple I am missing?

  6. #6
    Join Date
    Sep 2010
    Posts
    7

    Default

    I think this is the build problem , please check the deployed resources on tomcat because some time its not refreshed ..

  7. #7
    Join Date
    Dec 2010
    Posts
    8

    Default

    I am using the lastest Spring and Quartz jars....

  8. #8
    Join Date
    Dec 2010
    Posts
    8

    Default

    Anyone else have an idea? Maybe a specific setting in the Quartz properties or in the bean?

  9. #9
    Join Date
    Dec 2010
    Posts
    8

    Default

    Figured out a solution with some help. Check out the thread in JavaRanch

  10. #10
    Join Date
    Dec 2010
    Posts
    1

    Default org.quartz.plugin.jobInitializer.overWriteExisting Jobs option

    You've got an option to set, to replace previous jobs declarations :

    org.quartz.plugin.jobInitializer.overWriteExisting Jobs = true

    => works in a quartz.properties file, so must work in your xml.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •