Announcement Announcement Module
Collapse
No announcement yet.
Spring job not restarting after crash Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring job not restarting after crash

    I have a job defined:

    Code:
    	<bean id="tasksManager" class="stu.events.managers.TasksManager">
    		<property name="dao" ref="daoFactory"/>
    		<property name="stuCache" ref="stuCache"/>
    		<property name="commonActions" ref="commonActions"/>
    	</bean>
    	
    <bean id="tasksManagerJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
      <property name="targetObject" ref="tasksManager" />
      <property name="targetMethod" value="runTimerTask" />
      <property name="concurrent" value="false" />
    </bean>
    
    
    <bean id="tasksManagerTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
        <!-- see the example of method invoking job above -->
        <property name="jobDetail" ref="tasksManagerJobDetail" />
        <!-- 10 seconds -->
        <property name="startDelay" value="10000" />
        <!-- repeat every 500 miliseconds -->
        <property name="repeatInterval" value="500" />
    </bean>
    
    <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="triggers">
            <list>
                <ref bean="tasksManagerTrigger" />
            </list>
        </property>
    </bean>
    This job executes every 500 miliseconds and checks if he has some tasks to perform. If not - does nothing, but if there is something - he manages those tasks.

    The problem is that when an exception is produced - the current job execution stops (which is expected behaviour...) BUT there will be no more executions after next 500 miliseconds!

    At least not on my tomcat 5.5.20 on linux... because on Windows XP with tomcat 5.5.23 it works as expected - if one execution crashes - it has no effect on the next one

    Code:
    2007-05-03 13:55:21,174 INFO [stu.events.managers.TasksManager] - <start processing>
    2007-05-03 13:55:21,175 INFO [stu.events.managers.TasksManager] - <setting time of the first task>
    2007-05-03 13:55:21,175 INFO [stu.events.managers.TasksManager] - <setting time of the first fleet>
    2007-05-03 13:55:21,175 INFO [stu.events.managers.TasksManager] - <Next action should be: 1178193323000>
    2007-05-03 13:55:21,175 INFO [stu.events.managers.TasksManager] - <finish processing>
    2007-05-03 13:55:21,175 INFO [stu.events.managers.TasksManager] - <remaining tasks: 380>
    2007-05-03 13:55:21,175 INFO [stu.events.managers.TasksManager] - <remaining fleets: 2>
    2007-05-03 13:55:21,677 INFO [stu.events.managers.TasksManager] - <start processing>
    2007-05-03 13:55:21,680 INFO [stu.events.managers.TasksManager] - <setting time of the first task>
    2007-05-03 13:55:21,681 INFO [stu.events.managers.TasksManager] - <setting time of the first fleet>
    2007-05-03 13:55:21,681 INFO [stu.events.managers.TasksManager] - <Next action should be: 1178193323000>
    2007-05-03 13:55:21,681 INFO [stu.events.managers.TasksManager] - <finish processing>
    2007-05-03 13:55:21,681 INFO [stu.events.managers.TasksManager] - <remaining tasks: 380>
    2007-05-03 13:55:21,681 INFO [stu.events.managers.TasksManager] - <remaining fleets: 2>
    2007-05-03 13:55:22,179 INFO [stu.events.managers.TasksManager] - <start processing>
    2007-05-03 13:55:22,180 INFO [stu.events.managers.TasksManager] - <setting time of the first task>
    2007-05-03 13:55:22,180 INFO [stu.events.managers.TasksManager] - <setting time of the first fleet>
    2007-05-03 13:55:22,180 INFO [stu.events.managers.TasksManager] - <Next action should be: 1178193323000>
    2007-05-03 13:55:22,180 INFO [stu.events.managers.TasksManager] - <finish processing>
    2007-05-03 13:55:22,180 INFO [stu.events.managers.TasksManager] - <remaining tasks: 380>
    2007-05-03 13:55:22,180 INFO [stu.events.managers.TasksManager] - <remaining fleets: 2>
    2007-05-03 13:55:22,666 INFO [stu.events.managers.TasksManager] - <start processing>
    2007-05-03 13:55:22,667 INFO [stu.events.managers.TasksManager] - <setting time of the first task>
    2007-05-03 13:55:22,667 INFO [stu.events.managers.TasksManager] - <setting time of the first fleet>
    2007-05-03 13:55:22,667 INFO [stu.events.managers.TasksManager] - <Next action should be: 1178193323000>
    2007-05-03 13:55:22,668 INFO [stu.events.managers.TasksManager] - <finish processing>
    2007-05-03 13:55:22,668 INFO [stu.events.managers.TasksManager] - <remaining tasks: 380>
    2007-05-03 13:55:22,668 INFO [stu.events.managers.TasksManager] - <remaining fleets: 2>

    Code:
    2007-05-03 13:55:23,178 INFO [stu.events.managers.TasksManager] - <start processing>
    2007-05-03 13:55:23,245 INFO [stu.events.managers.TasksManager] - <setting time of the first task>
    2007-05-03 13:55:23,245 INFO [stu.events.managers.TasksManager] - <setting time of the first fleet>
    2007-05-03 13:55:23,246 INFO [stu.events.managers.TasksManager] - <Next action should be: 1178193323000>
    2007-05-03 13:55:23,246 INFO [stu.events.managers.TasksManager] - <loop if>
    2007-05-03 13:55:23,246 INFO [stu.events.managers.TasksManager] - <there are tasks>
    2007-05-03 13:55:23,246 INFO [stu.events.managers.TasksManager] - <we will be processing flee: 26720>
    2007-05-03 13:55:23,303 INFO [stu.events.managers.TasksManager] - <processing fleet ----- 26720>
    2007-05-03 13:55:23,303 INFO [stu.events.managers.TasksManager] - <processing fleet ms ----- S>

    for this issue - i don't care what kind of exception i will get (may it be the one i posted, maybe some problems with connection to the database or maybe some exception related to a specific task (which i have or will have many types). i just care for the job to be executing always.

    Code:
    2007-05-03 13:55:23,726 ERROR [org.hibernate.util.JDBCExceptionReporter] - <Cannot delete or update a parent row: a foreign key constraint fails (`stu/stu_pl
    anet_ship`, CONSTRAINT `stu_planet_ship_ibfk_4` FOREIGN KEY (`ship_fleet_id`) REFERENCES `stu_player_fleet` (`fleet_id`))>
    2007-05-03 13:55:23,726 ERROR [org.hibernate.event.def.AbstractFlushingEventListener] - <Could not synchronize database state with session>
    org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
            at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
            at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
            at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:249)
            at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
            at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:144)
            at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
            at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
            at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
            at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
            at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
            at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:54)
            at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:416)
            at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:540)
            at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:510)
            at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:310)
            at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:117)
            at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
            at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:209)
            at $Proxy69.delete(Unknown Source)
            at stu.events.managers.TasksManager.processFleet(TasksManager.java:654)
            at stu.events.managers.TasksManager.processFleet(TasksManager.java:459)
            at stu.events.managers.TasksManager.processLists(TasksManager.java:410)
            at stu.events.managers.TasksManager.runTimerTask(TasksManager.java:112)
            at sun.reflect.GeneratedMethodAccessor209.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:270)
            at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java
    :212)
            at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:79)
            at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
            at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:529)
    Caused by: java.sql.BatchUpdateException: Cannot delete or update a parent row: a foreign key constraint fails (`stu/stu_planet_ship`, CONSTRAINT `stu_planet
    _ship_ibfk_4` FOREIGN KEY (`ship_fleet_id`) REFERENCES `stu_player_fleet` (`fleet_id`))

    the real question is - why on Windows the next job is triggered and on linux - it is not.

    Will it help to try-catch the whole method that is defined in the job? (i guess i will try this one right away, but my problem is urgent to me and i'd appreciate some input from those who might be experienced in that area)

    Cheers,
    Fox

  • #2
    try-catch worked

    Comment

    Working...
    X