1

我遇到了一个 Web 应用程序的问题,该应用程序抛出 java.net.SocketException: Connection reset 异常。我相信抛出这个异常是因为客户端在从服务器发回响应之前关闭了连接。我无法在具有相同设置的开发环境中重新创建此问题。我重新启动tomcat后它工作正常,但应用程序在一段时间后开始抛出此异常。我怀疑我管理数据库连接池的方式,但正如我之前提到的那样,我无法重新创建这个问题。

 org.springframework.dao.DataAccessResourceFailureException: could not execute query; nested exception is org.hibernate.exception.JDBCConnectionException: could not execute query
    at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:625) ~[spring-orm-3.0.1.RELEASE.jar:3.0.1.RELEASE]
    at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412) ~[spring-orm-3.0.1.RELEASE.jar:3.0.1.RELEASE]
    at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411) ~[spring-orm-3.0.1.RELEASE.jar:3.0.1.RELEASE]
    at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374) ~[spring-orm-3.0.1.RELEASE.jar:3.0.1.RELEASE]
    at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:912) ~[spring-orm-3.0.1.RELEASE.jar:3.0.1.RELEASE]
    at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:904) ~[spring-orm-3.0.1.RELEASE.jar:3.0.1.RELEASE]
    at edu.ucla.iamucla.tools.shibboleth.manager.dao.hibernate.ApplicationGroupDaoHibernate.getAllApplicationGroups(ApplicationGroupDaoHibernate.java:73) ~[ApplicationGroupDaoHibernate.class:na]
    at edu.ucla.iamucla.tools.shibboleth.manager.web.HomeController.getApplicationGroups(HomeController.java:74) ~[HomeController.class:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0_19]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) ~[na:1.6.0_19]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0_19]
    at java.lang.reflect.Method.invoke(Method.java:597) ~[na:1.6.0_19]
    at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.doInvokeMethod(HandlerMethodInvoker.java:710) ~[spring-web-3.0.1.RELEASE.jar:3.0.1.RELEASE]
    at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:152) ~[spring-web-3.0.1.RELEASE.jar:3.0.1.RELEASE]
    at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:414) ~[spring-webmvc-3.0.1.RELEASE.jar:3.0.1.RELEASE]
    at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:402) ~[spring-webmvc-3.0.1.RELEASE.jar:3.0.1.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771) ~[spring-webmvc-3.0.1.RELEASE.jar:3.0.1.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716) ~[spring-webmvc-3.0.1.RELEASE.jar:3.0.1.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647) [spring-webmvc-3.0.1.RELEASE.jar:3.0.1.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552) [spring-webmvc-3.0.1.RELEASE.jar:3.0.1.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) [servlet-api.jar:na]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) [servlet-api.jar:na]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) [catalina.jar:6.0.26]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:6.0.26]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) [catalina.jar:6.0.26]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) [catalina.jar:6.0.26]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) [catalina.jar:6.0.26]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [catalina.jar:6.0.26]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [catalina.jar:6.0.26]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) [catalina.jar:6.0.26]
    at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190) [tomcat-coyote.jar:6.0.26]
    at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:291) [tomcat-coyote.jar:6.0.26]
    at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:769) [tomcat-coyote.jar:6.0.26]
    at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:698) [tomcat-coyote.jar:6.0.26]
    at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:891) [tomcat-coyote.jar:6.0.26]
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690) [tomcat-coyote.jar:6.0.26]
    at java.lang.Thread.run(Thread.java:619) [na:1.6.0_19]
Caused by: org.hibernate.exception.JDBCConnectionException: could not execute query
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:74) ~[hibernate-3.2.6.ga.jar:3.2.6.ga]
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) ~[hibernate-3.2.6.ga.jar:3.2.6.ga]
    at org.hibernate.loader.Loader.doList(Loader.java:2216) ~[hibernate-3.2.6.ga.jar:3.2.6.ga]
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104) ~[hibernate-3.2.6.ga.jar:3.2.6.ga]
    at org.hibernate.loader.Loader.list(Loader.java:2099) ~[hibernate-3.2.6.ga.jar:3.2.6.ga]
    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378) ~[hibernate-3.2.6.ga.jar:3.2.6.ga]
    at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338) ~[hibernate-3.2.6.ga.jar:3.2.6.ga]
    at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172) ~[hibernate-3.2.6.ga.jar:3.2.6.ga]
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121) ~[hibernate-3.2.6.ga.jar:3.2.6.ga]
    at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79) ~[hibernate-3.2.6.ga.jar:3.2.6.ga]
    at org.springframework.orm.hibernate3.HibernateTemplate$30.doInHibernate(HibernateTemplate.java:921) ~[spring-orm-3.0.1.RELEASE.jar:3.0.1.RELEASE]
    at org.springframework.orm.hibernate3.HibernateTemplate$30.doInHibernate(HibernateTemplate.java:1) ~[spring-orm-3.0.1.RELEASE.jar:3.0.1.RELEASE]
    at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406) ~[spring-orm-3.0.1.RELEASE.jar:3.0.1.RELEASE]
    ... 34 common frames omitted
Caused by: java.sql.SQLException: I/O Error: Connection reset
    at net.sourceforge.jtds.jdbc.TdsCore.executeSQL(TdsCore.java:1053) ~[jtds-1.2.4.jar:1.2.4]
    at net.sourceforge.jtds.jdbc.TdsCore.microsoftPrepare(TdsCore.java:1179) ~[jtds-1.2.4.jar:1.2.4]
    at net.sourceforge.jtds.jdbc.ConnectionJDBC2.prepareSQL(ConnectionJDBC2.java:693) ~[jtds-1.2.4.jar:1.2.4]
    at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeQuery(JtdsPreparedStatement.java:777) ~[jtds-1.2.4.jar:1.2.4]
    at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:92) ~[commons-dbcp-1.2.1.jar:1.2.1]
    at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:92) ~[commons-dbcp-1.2.1.jar:1.2.1]
    at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186) ~[hibernate-3.2.6.ga.jar:3.2.6.ga]
    at org.hibernate.loader.Loader.getResultSet(Loader.java:1787) ~[hibernate-3.2.6.ga.jar:3.2.6.ga]
    at org.hibernate.loader.Loader.doQuery(Loader.java:674) ~[hibernate-3.2.6.ga.jar:3.2.6.ga]
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236) ~[hibernate-3.2.6.ga.jar:3.2.6.ga]
    at org.hibernate.loader.Loader.doList(Loader.java:2213) ~[hibernate-3.2.6.ga.jar:3.2.6.ga]
    ... 44 common frames omitted
Caused by: java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:168) ~[na:1.6.0_19]
    at java.io.DataInputStream.readFully(DataInputStream.java:178) ~[na:1.6.0_19]
    at java.io.DataInputStream.readFully(DataInputStream.java:152) ~[na:1.6.0_19]
    at net.sourceforge.jtds.jdbc.SharedSocket.readPacket(SharedSocket.java:842) ~[jtds-1.2.4.jar:1.2.4]
    at net.sourceforge.jtds.jdbc.SharedSocket.getNetPacket(SharedSocket.java:723) ~[jtds-1.2.4.jar:1.2.4]
    at net.sourceforge.jtds.jdbc.ResponseStream.getPacket(ResponseStream.java:466) ~[jtds-1.2.4.jar:1.2.4]
    at net.sourceforge.jtds.jdbc.ResponseStream.read(ResponseStream.java:103) ~[jtds-1.2.4.jar:1.2.4]
    at net.sourceforge.jtds.jdbc.ResponseStream.peek(ResponseStream.java:88) ~[jtds-1.2.4.jar:1.2.4]
    at net.sourceforge.jtds.jdbc.TdsCore.wait(TdsCore.java:3932) ~[jtds-1.2.4.jar:1.2.4]
    at net.sourceforge.jtds.jdbc.TdsCore.executeSQL(TdsCore.java:1046) ~[jtds-1.2.4.jar:1.2.4]
    ... 54 common frames omitted

以前的开发人员正在将日志写入控制台,这导致了一个非常大的 catalina.out 文件。我不确定这如何导致异常,但这是我看到的唯一奇怪的事情。以下是我的数据库配置。

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="${jdbc.driverClassName.sqlserver}"/>
    <property name="url" value="${jdbc.url.sqlserver}"/>
    <property name="username" value="${jdbc.username.sqlserver}"/>
    <property name="password" value="${jdbc.password.sqlserver}"/>
    <property name="maxActive" value="${jdbc.pool.maxActive}" />
    <property name="maxWait" value="${jdbc.pool.maxWait}" />
    <property name="initialSize" value="${jdbc.pool.initialSize}" />
    <property name="maxIdle" value="${jdbc.pool.maxIdle}" />

    <property name="poolPreparedStatements" value="true"/>
    <property name="defaultAutoCommit" value="true"/>


</bean>

如果有人能对这个问题有所了解,我会很高兴,我正在使用 Spring 3.x、Hibernate、SQL Server、tomcat6。

4

0 回答 0