NullPointerException 与 Quartz & 春天

发布于 2024-07-24 14:56:22 字数 660 浏览 8 评论 0原文

我正在使用 Spring Quartz 集成,每次我尝试关闭 Tomcat 时,Quartz 进程都无法关闭。 这是堆栈跟踪:

Exception in thread "org.springframework.scheduling.quartz.SchedulerFactoryBean#0_QuartzSchedulerThread" 
        java.lang.NullPointerException
    at org.apache.commons.logging.LogFactory.getCachedFactory(LogFactory.java:979)
    at org.apache.commons.logging.LogFactory.getFactory(LogFactory.java:435)
    at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:685)
    at org.quartz.core.QuartzSchedulerThread.getLog(QuartzSchedulerThread.java:475)
    at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:404)

以前有人看过这个吗?

I'm using the Spring Quartz integration, and every time I try to shut down Tomcat, the Quartz processes fail to shut down. This is the stack trace:

Exception in thread "org.springframework.scheduling.quartz.SchedulerFactoryBean#0_QuartzSchedulerThread" 
        java.lang.NullPointerException
    at org.apache.commons.logging.LogFactory.getCachedFactory(LogFactory.java:979)
    at org.apache.commons.logging.LogFactory.getFactory(LogFactory.java:435)
    at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:685)
    at org.quartz.core.QuartzSchedulerThread.getLog(QuartzSchedulerThread.java:475)
    at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:404)

Has anyone seem this before?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

居里长安 2024-07-31 14:56:22

如果您查看 SchedulerFactoryBean,它有一个名为 waitForJobsToCompleteOnShutdown 的属性。 当 Spring ApplicationContext 收到关闭请求时,它会告诉 Quartz Scheduler 关闭,有条件地告诉它等待所有作业完成后再关闭。

但是,如果 Spring 收到 Tomcat 上下文被释放的通知,它只能处理关闭请求(并告诉 Quartz)关闭。 你如何在 Tomcat 中使用 Spring? 您是否注册了 ServletContextListener 来调用 applicationContext.destroy()

实际的 NPE 可能是由 Tomcat 在关闭时将应用程序运行所在的类加载器中的所有 static 引用设置为 null 引起的。 这样做是为了帮助防止 Tomcat 回收/重新启动期间出现任何内存泄漏。 但是,如果您的 Tomcat 容器中存在仍在运行的线程(因为它们没有正确关闭,例如您的 Quartz 线程),那么当该线程中的代码(例如您的 Quartz 线程中的代码)运行时,您将看到错误。试图访问其记录器的石英线程(可能保留为静态)尝试访问已被清空的任何静态引用。

If you look at SchedulerFactoryBean, it has a property named waitForJobsToCompleteOnShutdown. When the Spring ApplicationContext receives the request to shut down, it tells the Quartz Scheduler to shut down, conditionally telling it to wait for all jobs to complete before shutting down.

But, Spring can only process the request to shutdown (and tell Quartz) to shutdown if it is notified of the Tomcat context being disposed. How are you using Spring within Tomcat? Do you have a ServletContextListener registered to call applicationContext.destroy() ?

The actual NPE is probably caused by Tomcat setting all static references within the classLoader that your application runs in to null on shutdown. It does this to help prevent any memory leaks during recycling/restarts of Tomcat. But, if you have threads that live on within the Tomcat container that are still running (because they were not properly shutdown, such as your Quartz threads), then you will see errors when the code within that thread (such as the code within your Quartz thread that tries to gain access to it's logger - which is likely kept as static) tries to access any static references that have been nulled out.

错爱 2024-07-31 14:56:22

您的 WAR 中是否有打包的 commons-logging 副本? 如果是这样,作为 Tomcat 一部分的副本与 WAR 中的副本之间可能会出现奇怪的交互。 尝试删除 WAR 副本,看看是否有帮助。

Do you have a copy of commons-logging packaged inside your WAR? If so, there may be an odd interaction between the copy that comes as part of Tomcat, and the copy that's in your WAR. Try removing the WAR copy and see if that helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文