`

c3p0.max_statements = 0 GooGooStatementCache Problem with checked-in Statement,

阅读更多

c3p0.max_statements不设置等于0时报如下错误

  1. INFO 2010-07-23 16:29:38,490 [com.mchange.v2.c3p0.stmt.GooGooStatementCache] - Problem with checked-in Statement, discarding.   
  2. java.lang.NullPointerException  

##
<!-- 最大连接数 -->
<property name="hibernate.c3p0.max_size">20</property>
<!-- 最小连接数 -->
<property name="hibernate.c3p0.min_size">5</property>
<!-- 获得连接的超时时间,如果超过这个时间,会抛出异常,单位毫秒 -->
<property name="hibernate.c3p0.timeout">120</property>
<!-- 最大的PreparedStatement的数量 -->
<property name="hibernate.c3p0.max_statements">0</property>
<!-- 每隔120秒检查连接池里的空闲连接 ,单位是秒-->
<property name="hibernate.c3p0.idle_test_period">120</property>
<!-- 当连接池里面的连接用完的时候,C3P0一下获取的新的连接数 -->
<property name="hibernate.c3p0.acquire_increment">2</property>
<!-- 每次都验证连接是否可用 -->
<property name="hibernate.c3p0.validate">true</property>
==========================================

“SEVERE: The last packet successfully received from the server was144382 seconds ago.The last packet sent successfully to the server was 144382 seconds ago, which is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.”
你的log里说的很清楚了。原因是Mysql服务器默认的“wait_timeout”是8小时,如果一个connection空闲超过8个小时,Mysql将自动断开该 connection,而C3P0并不知道该connection已经失效,如果这时请求connection,将会造成上面的异常。你每次使用前判断connection是否有效就会避免这种异常。

解决的方法有3种:

增加wait_timeout的时间。
减少Connection pools中connection的lifetime。
测试Connection pools中connection的有效性。
当然最好的办法是同时综合使用上述3种方法,下面举个例子,假设wait_timeout为默认的8小时

C3P0增加以下配置信息:

//获取connnection时测试是否有效
testConnectionOnCheckin = true
//自动测试的table名称

automaticTestTable=C3P0TestTable

//set to something much less than wait_timeout, prevents connections from going stale
idleConnectionTestPeriod = 18000
//set to something slightly less than wait_timeout, preventing 'stale' connections from being handed out
maxIdleTime = 25000
//if you can take the performance 'hit', set to "true"
testConnectionOnCheckout = true

===================================

1、org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed.

问题:hibernate3默认的lazy为true,使用代理模式proxy属性允许延迟加载类的持久化实例。调用session.load()方法,Hibernate开始会返回CGLIB代理,除主键外的其他值均为null。当代理的某个方法被实际调用的时候, 真实的持久化对象才会被装载,但必须在同一个session中。如session.close()前一直未调用方法,close()后再调用,报上述错误。

解决:a.hbm.xml中 class项,加上lazy=false

             b.使用session.get()方法,将不延迟,直接取出对象实例。

2、java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Can't start a cloned connection while in manual transaction mode.

问题:ms SQLserver在设置为autoCommit=false,SelectMethod=direct时,处理多个statement将报该错

解决:在url加上设置SelectMethod=Cursor

3、java.lang.NullPointerException: Problem with checked-in Statement, discarding.

问题:oracle9i前的jdbc Driver有bug,多个statement亦会出错

解决:在http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/index.html上下载最新的ojdbc14.jar,版本为10.2.0.1.0

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics