Announcement Announcement Module
Collapse
No announcement yet.
Spring and Quartz - can't update Triggers Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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>

    Comment


    • #3
      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"?

      Comment


      • #4
        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

        Comment


        • #5
          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?

          Comment


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

            Comment


            • #7
              I am using the lastest Spring and Quartz jars....

              Comment


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

                Comment


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

                  Comment


                  • #10
                    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.

                    Comment

                    Working...
                    X