我公司有一个 Web 应用程序,允许用户作为其业务流程的一部分将大型文档(10+ MB)上传到该应用程序中。对于快速连接,它工作得很好,文档可以成功加载到 Oracle 数据库中。如果连接速度很慢,那么我们会在日志中收到以下堆栈跟踪,并且文档无法上传到数据库中:
2014-01-22 11:44:46,085 [XXX ERROR] [XXXXX.controller.BaseRequestProcessor 231] com.XXXXX.XXXXX.exception.DataAccessException: java.lang.NullPointerException
com.XXXXX.XXXXX.exception.DataAccessException: java.lang.NullPointerException
at com.XXXXX.XXXXX.dao.SessionManager.rollback(SessionManager.java:258)
at com.XXXXX.XXXXX.tracking.service.TrackingService.requestUpdateChild(TrackingService.java:1354)
at com.XXXXX.XXXXX.tracking.controller.action.TrackingAction.prepareUpdate(TrackingAction.java:711)
at com.XXXXX.XXXXX.tracking.controller.action.TrackingAction.requestUpdate(TrackingAction.java:639)
at sun.reflect.GeneratedMethodAccessor726.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:274)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:194)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.XXXXX.XXXXX.web.filter.AuthenticationFilter.continueProcessing(AuthenticationFilter.java:256)
at com.XXXXX.XXXXX.web.filter.AuthenticationFilter.doFilter(AuthenticationFilter.java:134)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.XXXXX.XXXXX.web.filter.CacheFilter.doFilter(CacheFilter.java:108)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.XXXXX.XXXXX.web.filter.TrackingStateFilter.doFilter(TrackingStateFilter.java:88)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.XXXXX.XXXXX.web.filter.ConcurrentUserFilter.doFilter(ConcurrentUserFilter.java:111)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:206)
at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:179)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.ajp.AjpAprProcessor.process(AjpAprProcessor.java:429)
at org.apache.coyote.ajp.AjpAprProtocol$AjpConnectionHandler.process(AjpAprProtocol.java:384)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1665)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at com.XXXXX.XXXXX.tracking.service.TrackingService.getWorkflowInstance(TrackingService.java:2283)
at com.XXXXX.XXXXX.tracking.service.TrackingService.requestUpdateChild(TrackingService.java:1305)
通常接下来是:
2014-01-22 12:02:44,235 [XXX ERROR] [hibernate.transaction.JDBCTransaction 232] Could not toggle autocommit
java.sql.SQLRecoverableException: Closed Connection
和
2014-01-22 12:02:44,236 [XXX ERROR] [hibernate.transaction.JDBCTransaction 202] JDBC rollback failed
java.sql.SQLRecoverableException: Closed Connection
我们一直在研究 Tomcat 连接设置,并将其设置为:
<Connector port="8080" protocol="HTTP/1.1" URIEncoding="UTF-8"
connectionUploadTimeout="36000000" disableUploadTimeout="false"
connectionTimeout="60000" redirectPort="8443" />
我认为这在某种程度上与 Tomcat 关闭与数据库的连接有关,因为上传文件需要很长时间。然后,当文件最终上传到 Tomcat 并且 Tomcat 尝试将文件提交到数据库时,由于连接已关闭,因此无法提交,因此失败。
有谁遇到过类似的问题并找到了解决方案?
谢谢!
答案1
从表面上看,至少 TrackingManager 类中可能存在错误,因为它会抛出 NullPointerException。这可能是原因,也可能是症状。
Hibernate 正在尝试回滚,但发现 DB 连接已关闭,因此无法回滚。
所以我想说您的代码、连接池或数据库过早关闭了连接。