Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process cannot exit when the SchedulerFactoryBean fails to initialize [SPR-16816] #21356

spring-issuemaster opened this issue May 12, 2018 · 2 comments


Copy link

@spring-issuemaster spring-issuemaster commented May 12, 2018

ScienJus opened SPR-16816 and commented

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(    at org.quartz.impl.jdbcjobstore.JobStoreSupport$12.execute(    at org.quartz.impl.jdbcjobstore.JobStoreCMT.executeInLock(    at org.quartz.impl.jdbcjobstore.JobStoreSupport.executeWithoutLock(    at org.quartz.impl.jdbcjobstore.JobStoreSupport.retrieveTrigger(    at org.quartz.core.QuartzScheduler.getTrigger(    at org.quartz.impl.StdScheduler.getTrigger(    at org.springframework.scheduling.quartz.SchedulerAccessor.addTriggerToScheduler(    at org.springframework.scheduling.quartz.SchedulerAccessor.registerJobsAndTriggers(    at org.springframework.scheduling.quartz.SchedulerFactoryBean.afterPropertiesSet(

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

Affects: 4.3.17, 5.0.6


Referenced from: pull request #1828, and commits 849b6cc, 0098245, a3bcdbe

Backported to: 4.3.18

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented May 13, 2018

ScienJus commented

hi @Juergen Hoeller , have you started working on it?If not, i wish to get it done.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented May 15, 2018

Juergen Hoeller commented

I ended up refactoring SchedulerFactoryBean a bit further, wrapping Scheduler initialization through a delegate and locally shutting down the Scheduler in afterPropertiesSet if necessary (since destroy() is only really meant for external lifecycle destruction signals).

This is on master now; I'll backport it to 5.0.x and 4.3.x tomorrow, along with a few other changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.