Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-16816

Process cannot exit when the SchedulerFactoryBean fails to initialize

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Complete
    • Affects Version/s: 4.3.17, 5.0.6
    • Fix Version/s: 4.3.18, 5.0.7, 5.1 RC1
    • Component/s: Task
    • Labels:
      None

      Description

      For some reason, there is an occasional exception arise from database queries when using quartz's cluster mode. when this exception occurs, the Spring container will close and exit, leaving Java Process suspending.

      Through the jstack logs I found that some quartz threads are still running. because they are user threads, the Java process does not exit.

      The threads are supposed to close through the `destroy` method in `SchedulerFactoryBean`, but unfortunately, if an exception is thrown in `afterPropertiesSet`, the `destroy` method will not be called, subsequently, these threads will not be closed in the meanwhile.

      Here are the jstack logs and error logs. You can see that `registerJobsAndTriggers` throws an exception after the scheduler started. So I prepare to catch the invokation of the method and manually call the destroy method when it throwing an exception.

      Caused by: org.quartz.JobPersistenceException: Couldn't retrieve trigger: No record found for selection of Trigger with key: 'DEFAULT.bikeLowPowerUpcomingJobTrigger' and statement: SELECT * FROM QRTZ_CRON_TRIGGERS WHERE SCHED_NAME = 'molaQuartzScheduler' AND TRIGGER_NAME = ? AND TRIGGER_GROUP = ?    at org.quartz.impl.jdbcjobstore.JobStoreSupport.retrieveTrigger(JobStoreSupport.java:1533)    at org.quartz.impl.jdbcjobstore.JobStoreSupport$12.execute(JobStoreSupport.java:1522)    at org.quartz.impl.jdbcjobstore.JobStoreCMT.executeInLock(JobStoreCMT.java:245)    at org.quartz.impl.jdbcjobstore.JobStoreSupport.executeWithoutLock(JobStoreSupport.java:3739)    at org.quartz.impl.jdbcjobstore.JobStoreSupport.retrieveTrigger(JobStoreSupport.java:1519)    at org.quartz.core.QuartzScheduler.getTrigger(QuartzScheduler.java:1530)    at org.quartz.impl.StdScheduler.getTrigger(StdScheduler.java:508)    at org.springframework.scheduling.quartz.SchedulerAccessor.addTriggerToScheduler(SchedulerAccessor.java:291)    at org.springframework.scheduling.quartz.SchedulerAccessor.registerJobsAndTriggers(SchedulerAccessor.java:235)    at org.springframework.scheduling.quartz.SchedulerFactoryBean.afterPropertiesSet(SchedulerFactoryBean.java:510)
      

      I‘d like to create a pull request if you agree with this solution.

        Attachments

          Activity

            People

            • Assignee:
              juergen.hoeller Juergen Hoeller
              Reporter:
              ScienJus ScienJus
              Last updater:
              Stéphane Nicoll
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                5 weeks, 3 days ago