比如一个简单的功能,比如设置一个数据为1和0,反复设置点击功能按钮,或者一个列表,上一页下一页反复频繁点击,大概30秒之内,就能导致项目出错并停止运行。出错提示如下。2009-07-31 08:19:44,109 WARN [org.hibernate.jdbc.ConnectionManager] - finalizing with closed connection
2009-07-31 08:19:46,140 WARN [org.hibernate.jdbc.ConnectionManager] - unclosed connection, forgot to call close() on your session?
2009-07-31 08:19:46,156 WARN [org.hibernate.jdbc.ConnectionManager] - finalizing with closed connection
2009-07-31 08:19:46,156 WARN [org.hibernate.jdbc.ConnectionManager] - unclosed connection, forgot to call close() on your session?
2009-07-31 08:19:46,156 WARN [org.hibernate.jdbc.ConnectionManager] - finalizing with closed connection
2009-07-31 08:19:48,937 WARN [org.hibernate.jdbc.ConnectionManager] - unclosed connection, forgot to call close() on your session?
2009-07-31 08:19:48,953 WARN [org.hibernate.jdbc.ConnectionManager] - unclosed connection, forgot to call close() on your session?
2009-07-31 08:19:48,968 WARN [org.hibernate.jdbc.ConnectionManager] - unclosed connection, forgot to call close() on your session?
2009-07-31 08:19:48,968 WARN [org.hibernate.jdbc.ConnectionManager] - finalizing with closed connection
2009-07-31 08:19:53,984 WARN [org.hibernate.util.JDBCExceptionReporter] - SQL Error: 0, SQLState: null
2009-07-31 08:19:53,984 ERROR [org.hibernate.util.JDBCExceptionReporter] - Cannot get a connection, pool exhausted
2009-07-31 08:19:53,984 WARN [org.hibernate.util.JDBCExceptionReporter] - SQL Error: 0, SQLState: null
2009-07-31 08:19:53,984 ERROR [org.hibernate.util.JDBCExceptionReporter] - Cannot get a connection, pool exhausted
2009-07-31 08:19:53,984 WARN [org.hibernate.util.JDBCExceptionReporter] - SQL Error: 0, SQLState: null
2009-07-31 08:19:53,984 ERROR [org.hibernate.util.JDBCExceptionReporter] - Cannot get a connection, pool exhausted
2009-07-31 08:19:53,984 WARN [org.hibernate.util.JDBCExceptionReporter] - SQL Error: 0, SQLState: null
2009-07-31 08:19:53,984 ERROR [org.hibernate.util.JDBCExceptionReporter] - Cannot get a connection, pool exhausted
2009-07-31 08:19:53,984 WARN [org.hibernate.util.JDBCExceptionReporter] - SQL Error: 0, SQLState: null
2009-07-31 08:19:53,984 ERROR [org.hibernate.util.JDBCExceptionReporter] - Cannot get a connection, pool exhausted
2009-07-31 08:19:53,984 WARN [org.hibernate.util.JDBCExceptionReporter] - SQL Error: 0, SQLState: null
2009-07-31 08:19:53,984 ERROR [org.hibernate.util.JDBCExceptionReporter] - Cannot get a connection, pool exhausted
org.hibernate.exception.GenericJDBCException: Cannot open connection
at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:301)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:110)
at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:88)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1162)
at org.hibernate.loader.Loader.doQuery(Loader.java:390)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.doList(Loader.java:1593)
at org.hibernate.loader.Loader.list(Loader.java:1577)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:395)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
请大家帮我看看,此类问题怎么解决?
代码已经按照标准来制作,正常使用下不会出错。何解?提供一个解决方法。谢谢。
2009-07-31 08:19:46,140 WARN [org.hibernate.jdbc.ConnectionManager] - unclosed connection, forgot to call close() on your session?
2009-07-31 08:19:46,156 WARN [org.hibernate.jdbc.ConnectionManager] - finalizing with closed connection
2009-07-31 08:19:46,156 WARN [org.hibernate.jdbc.ConnectionManager] - unclosed connection, forgot to call close() on your session?
2009-07-31 08:19:46,156 WARN [org.hibernate.jdbc.ConnectionManager] - finalizing with closed connection
2009-07-31 08:19:48,937 WARN [org.hibernate.jdbc.ConnectionManager] - unclosed connection, forgot to call close() on your session?
2009-07-31 08:19:48,953 WARN [org.hibernate.jdbc.ConnectionManager] - unclosed connection, forgot to call close() on your session?
2009-07-31 08:19:48,968 WARN [org.hibernate.jdbc.ConnectionManager] - unclosed connection, forgot to call close() on your session?
2009-07-31 08:19:48,968 WARN [org.hibernate.jdbc.ConnectionManager] - finalizing with closed connection
2009-07-31 08:19:53,984 WARN [org.hibernate.util.JDBCExceptionReporter] - SQL Error: 0, SQLState: null
2009-07-31 08:19:53,984 ERROR [org.hibernate.util.JDBCExceptionReporter] - Cannot get a connection, pool exhausted
2009-07-31 08:19:53,984 WARN [org.hibernate.util.JDBCExceptionReporter] - SQL Error: 0, SQLState: null
2009-07-31 08:19:53,984 ERROR [org.hibernate.util.JDBCExceptionReporter] - Cannot get a connection, pool exhausted
2009-07-31 08:19:53,984 WARN [org.hibernate.util.JDBCExceptionReporter] - SQL Error: 0, SQLState: null
2009-07-31 08:19:53,984 ERROR [org.hibernate.util.JDBCExceptionReporter] - Cannot get a connection, pool exhausted
2009-07-31 08:19:53,984 WARN [org.hibernate.util.JDBCExceptionReporter] - SQL Error: 0, SQLState: null
2009-07-31 08:19:53,984 ERROR [org.hibernate.util.JDBCExceptionReporter] - Cannot get a connection, pool exhausted
2009-07-31 08:19:53,984 WARN [org.hibernate.util.JDBCExceptionReporter] - SQL Error: 0, SQLState: null
2009-07-31 08:19:53,984 ERROR [org.hibernate.util.JDBCExceptionReporter] - Cannot get a connection, pool exhausted
2009-07-31 08:19:53,984 WARN [org.hibernate.util.JDBCExceptionReporter] - SQL Error: 0, SQLState: null
2009-07-31 08:19:53,984 ERROR [org.hibernate.util.JDBCExceptionReporter] - Cannot get a connection, pool exhausted
org.hibernate.exception.GenericJDBCException: Cannot open connection
at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:301)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:110)
at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:88)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1162)
at org.hibernate.loader.Loader.doQuery(Loader.java:390)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.doList(Loader.java:1593)
at org.hibernate.loader.Loader.list(Loader.java:1577)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:395)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
请大家帮我看看,此类问题怎么解决?
代码已经按照标准来制作,正常使用下不会出错。何解?提供一个解决方法。谢谢。
<property name="hibernate.connection.username">
sa
</property>
所有的property元素都不要换行 试一下
<property name="hibernate.connection.username">sa</property>
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:comp/env/jdbc/ssh_test</value>
</property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.connection.autocommit">true</prop> <prop key="hibernate.show_sql">false</prop>
</props>
</property> <property name="mappingResources">
<list>
<value>com/wj/vo/Article.hbm.xml</value>
</property>
</bean>数据连接部分,只要正常操作肯定没问题。
你有操作没有关闭session
unclosed connection, forgot to call close() on your session? --未关闭连接或连接未正常关闭
Cannot get a connection, pool exhausted --麽有连接可用喽~一直重复关闭连接 但是却没有调用close方法 导致连接池内的连接已满 已经不能在建立新的连接 。检查 获得conn和关闭conn那块 看是不是有什么不妥的地方在频繁操作的时候 不会释放资源呢
request.setAttribute("lineSize", lineSize);
request.setAttribute("allRecorders", allRecorders);
request.setAttribute("all", all);
request.setAttribute("flagname", "mode");
request.setAttribute("flagvalue", mode);
request.setAttribute("jspUrl", "article.do");
request.setAttribute("action", "list");列表部分也就利用到这些参数传递,应该没有使用session的。是不是列表的list.jsp页面,需要在最后一行关闭数据连接?若是的话,请问怎么做才合适?
String hql = "DELETE FROM Hd WHERE id=?";
Query q = super.getSession().createQuery(hql);
q.setInteger(0, id);
q.executeUpdate();
} public void insert(Hd hd) throws Exception {
super.getSession().save(hd);
}代码如上,怎么在其中关闭session,怎么写?
String hql = "DELETE FROM Hd WHERE id=?";
Query q = super.getSession().createQuery(hql);
q.setInteger(0, id);
q.executeUpdate();
super.getSession().close();
}
try{ } catch() finally{connection.close(); }
在
<bean id="dataSource"
class="org.springframework.jndi.JndiObjectFactoryBean"> 加destroy-method="close"
<property name="jndiName">
<value>java:comp/env/jdbc/ssh_test </value>
</property>
</bean>
{
saveToken(request); //重新获得令牌
throw new BossGlobalException("common.error.duplicatesubmit",
null);
}
建议在获取数据库连接,创建session的方法之前
加个if判断语句,来判断一下session是否关闭
要是没有先关闭再建立新的session