使用 Glassfish 和 Apache DBCP 与 Spring 连接池挂起

发布于 2024-08-29 00:40:10 字数 7625 浏览 5 评论 0原文

我们有一个 Spring 应用程序,它使用 Apache DBCP 进行连接池。我们的应用程序已经投入生产近一年了,没有出现任何问题。然而,在过去几周内,该应用程序已多次冻结。 (冻结是指不处理任​​何请求。)通过重新启动托管应用程序的 Glassfish 域可以暂时解决该问题。

我们正在监控该应用程序的内存(堆+非堆)和CPU利用率。这里似乎没有什么异常。然而,我们注意到,当我们重新启动域时,我们会在日志文件中收到类似于本文底部的异常消息。

我指出我们正在使用 DBCP,因为每个 NPE 都会在堆栈顶部报告borrowObject 方法。在任何应用程序关闭期间,它们都在同一毫秒内发生。

我们注意到过去发生过几次这种情况(此类 NPE 导致的关闭),但当应用程序冻结时,总是会发生五次。我们认为这并非巧合,处理应用程序请求的 HTTPSSLWorkerThreads 数量相同。

如果有人知道导致此问题的原因以及如何解决它,我们将不胜感激。

[#|2009-09-27T12:17:12.209-0400|SEVERE|sun-appserver9.1|javax.enterprise.system.container.web|_ThreadID=20;_ThreadName=httpSSLWorkerThread-443-4;_RequestID=25b115cb-de08-4ad4-bfdb-f76eb13b4bbe;|StandardWrapperValve[spring-dispatcher]: PWC1406: Servlet.service() for servlet spring-dispatcher threw exception
java.lang.NullPointerException
  at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:788)
  at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:95)
  at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)
  at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:113)
  at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:79)
  at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:552)
  at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:616)
  at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:645)
  at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:653)
  at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:685)
  at org.springframework.jdbc.core.simple.SimpleJdbcTemplate.query(SimpleJdbcTemplate.java:187)
  at stimpl.dao.ProjectDAO.getSearchResults(ProjectDAO.java:153)
  at stimpl.service.StimPlService.getSearchResults(StimPlService.java:69)
  at stimpl.mvc.search.ShowResultsController.handleRequestInternal(ShowResultsController.java:44)
  at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
  at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
  at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:874)
  at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:808)
  at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:476)
  at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:431)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:718)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
  at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:317)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
  at org.acegisecurity.securechannel.ChannelProcessingFilter.doFilter(ChannelProcessingFilter.java:138)
  at org.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:98)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
  at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:265)
  at org.acegisecurity.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:107)
  at org.acegisecurity.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:72)
  at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
  at org.acegisecurity.ui.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:124)
  at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
  at org.acegisecurity.providers.anonymous.AnonymousProcessingFilter.doFilter(AnonymousProcessingFilter.java:125)
  at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
  at org.acegisecurity.wrapper.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:81)
  at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
  at org.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:271)
  at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
  at org.acegisecurity.ui.logout.LogoutFilter.doFilter(LogoutFilter.java:110)
  at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
  at org.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:249)
  at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
  at org.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java:149)
  at org.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:98)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:288)
  at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:271)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:202)
  at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
  at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
  at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:206)
  at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
  at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
  at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
  at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:150)
  at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
  at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
  at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
  at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
  at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:270)
  at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:637)
  at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:568)
  at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:813)
  at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:339)
  at com.sun.enterprise.web.connector.grizzly.ssl.SSLReadTask.process(SSLReadTask.java:440)
  at com.sun.enterprise.web.connector.grizzly.ssl.SSLReadTask.doTask(SSLReadTask.java:228)
  at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
  at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
|#]

We have a Spring application that uses Apache DBCP for connection pooling. Our app has been in production for almost a year with no problems. However, during the past few weeks, the application has frozen a number of times. (By frozen, I mean no requests are handled.) The problem is temporarily fixed by restarting the Glassfish domain that hosts the app.

We are monitoring the memory (heap + nonheap) and CPU utilization of this application. Nothing seems out of the ordinary here. We have noticed however, that when we restart the domain, we get exception messages similar to the one at the bottom of this post in our log files.

I point out that we are using DBCP, because each of this NPEs reports the borrowObject method at the top of the stack. Each of them occurs within the same millisecond during any application shutdown.

We have noticed that there are a couple of these happening in the past (a shutdown with such an NPE), but when the application freezes, there are always five. This, we don't believe to be coincidental, is the same number of HTTPSSLWorkerThreads handling requests to the application.

If anyone knows what is causing this, and how to fix it, help would be greatly appreciated.

[#|2009-09-27T12:17:12.209-0400|SEVERE|sun-appserver9.1|javax.enterprise.system.container.web|_ThreadID=20;_ThreadName=httpSSLWorkerThread-443-4;_RequestID=25b115cb-de08-4ad4-bfdb-f76eb13b4bbe;|StandardWrapperValve[spring-dispatcher]: PWC1406: Servlet.service() for servlet spring-dispatcher threw exception
java.lang.NullPointerException
  at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:788)
  at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:95)
  at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)
  at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:113)
  at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:79)
  at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:552)
  at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:616)
  at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:645)
  at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:653)
  at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:685)
  at org.springframework.jdbc.core.simple.SimpleJdbcTemplate.query(SimpleJdbcTemplate.java:187)
  at stimpl.dao.ProjectDAO.getSearchResults(ProjectDAO.java:153)
  at stimpl.service.StimPlService.getSearchResults(StimPlService.java:69)
  at stimpl.mvc.search.ShowResultsController.handleRequestInternal(ShowResultsController.java:44)
  at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
  at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
  at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:874)
  at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:808)
  at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:476)
  at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:431)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:718)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
  at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:317)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
  at org.acegisecurity.securechannel.ChannelProcessingFilter.doFilter(ChannelProcessingFilter.java:138)
  at org.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:98)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
  at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:265)
  at org.acegisecurity.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:107)
  at org.acegisecurity.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:72)
  at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
  at org.acegisecurity.ui.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:124)
  at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
  at org.acegisecurity.providers.anonymous.AnonymousProcessingFilter.doFilter(AnonymousProcessingFilter.java:125)
  at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
  at org.acegisecurity.wrapper.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:81)
  at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
  at org.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:271)
  at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
  at org.acegisecurity.ui.logout.LogoutFilter.doFilter(LogoutFilter.java:110)
  at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
  at org.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:249)
  at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
  at org.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java:149)
  at org.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:98)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:288)
  at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:271)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:202)
  at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
  at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
  at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:206)
  at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
  at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
  at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
  at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:150)
  at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
  at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
  at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
  at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
  at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:270)
  at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:637)
  at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:568)
  at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:813)
  at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:339)
  at com.sun.enterprise.web.connector.grizzly.ssl.SSLReadTask.process(SSLReadTask.java:440)
  at com.sun.enterprise.web.connector.grizzly.ssl.SSLReadTask.doTask(SSLReadTask.java:228)
  at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
  at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
|#]

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

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

发布评论

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

评论(2

撩发小公举 2024-09-05 00:40:10

不幸的是,DBCP 因死锁而臭名昭著,尽管最近进行了重写工作。或者,您可以尝试(更快)不同的池,例如 BoneCP:http://jolbox.com

DBCP is infamous with deadlocks unfortunately though recently there's been a rewrite effort. Alternately you could try a (faster) different pool such as BoneCP: http://jolbox.com.

萌化 2024-09-05 00:40:10

如果其他人偶然发现这个问题,答案就在这里

In case someone else stumbles on to this question, the answer is here.

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