日期:2014-05-20  浏览次数:20766 次

(Tomcat+SSH+C3P0)==郁闷?不给分:100分
1、最近用Tomcat挂个网站,说实话,网站规模小,访问量也很低,但频繁死机,观察win2003 Server任务管理器发现:

(1)进程sqlsvr.exe内存使用常在200M以上
(2)进程TomcatW.exe内存使用在110M左右
(3)java.exe内存使用在20-80M左右

2、这样过一段时间就造成Tomcat假死,后台报打不开数据库连接错误,其实应该是内存溢出错误
使用的SSh框架做的网站,Spring2.0+Hibernate3.1+Struts1.2,由于本多次求助未果,本人强烈怀疑SSH配置问题,尤其是c3p0配置问题,故将关键Hibernate C3p0配置代码如下:
  <!-- C3P0配置 -->
<property name="c3p0.max_size">800</property>
<property name="c3p0.min_size">200</property>
<!--连接超时时间-->
<property name="c3p0.timeout">1000</property>
<!-- 每隔100秒检测连接是否可正常使用 -->
<property name="c3p0.idle_test_period">100</property>
  <!--当池中的连接耗尽的时候,一次性增加的连接数量,默认为3-->
<property name="hibernate.c3p0.acquire_increment">30</property>
<!--statemnets缓存大小-->
<property name="c3p0.max_statements">200</property>
<!-- c3p0 End -->
<!--其他配置-->
<property name="hibernate.connection.autocommit">true</property>
<property name="hibernate.jdbc.use_scrollable_resultset">
true
</property>
<property name="default_batch_fetch_size">20</property>

3、Tomcat内存设置如下:
  Initial Memory Pool : 256M
  Maximum Memory pool: 768M
  Thread Stack Size: 8192K
4、异常信息:
(1) 2009-09-05 09:28:05,000 [org.hibernate.util.JDBCExceptionReporter]-[ERROR] An SQLException was provoked by the following failure: java.lang.InterruptedException
org.hibernate.exception.GenericJDBCException: Cannot open connection
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
  。。。
 Caused by: java.sql.SQLException: An SQLException was provoked by the following failure: java.lang.InterruptedException
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:104)
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:65)
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:62)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:238)
at com.mchange.v2.c3p0.PoolBackedDataSource.getConnection(PoolBackedDataSource.java:94)
at org.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:35)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:417)
... 41 more
Caused by: java.lang.InterruptedException
at java.lang.Object.wait(Native Method)
at com.mchange.v2.resourcepool.BasicResourcePool.awaitAcquire(BasicResourcePool.java:966)
at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:208)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:232)
... 44 more
org.hibernate.exception.GenericJDBCException: Cannot open connection
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
5、救命。。。

------解决方案--------------------
http://www.zxbc.cn/html/20080716/63286.html

参考一下看有没有帮助
------解决方案--------------------
HibernateTemplate里定义一个public的returnSession方法,完后在InfoDAO中调用后再关闭不行吗,或者你直接在HibernateTemplate中写个关闭session的方法,再在InfoDAO中调用不行吗?
------解决方案--------------------