cpds.setIdleConnectionTestPeriod(18000);
            cpds.setTestConnectionOnCheckout(true);
            cpds.setTestConnectionOnCheckin(true);-------------------------------->cpds.setIdleConnectionTestPeriod(60);
            //cpds.setTestConnectionOnCheckout(true);
            //cpds.setTestConnectionOnCheckin(true);

解决方案 »

  1.   

    或者试试
    automaticTestTable属性
      

  2.   


    //注释掉意思是不是拿连接的时候不检查 能不能用直接拿?
    cpds.setTestConnectionOnCheckin(true);-------------------------------->cpds.setIdleConnectionTestPeriod(60);//cpds.setTestConnectionOnCheckout(true);//cpds.setTestConnectionOnCheckin(true);
    啥意思啊
      

  3.   

    IdleConnectionTestPeriod
    和TestConnectionOnCheckin ,TestConnectionOnCheckin可能有冲突,
    IdleConnectionTestPeriod设为18000时间太长了
    这几个属性的意思你晓得吧
      

  4.   

    idleConnectionTestPeriod:隔多少秒检查所有连接池中的空闲连接,默认为0表示不检查;     testConnectionOnCheckout:因性能消耗大请只在需要的时候使用它。如果设为true那么在每个connection提交的时候都将校验其有效性。建议使用idleConnectionTestPeriod或automaticTestTable 
    等方法来提升连接测试的性能。默认为false; 
        testConnectionOnCheckin:如果设为true那么在取得连接的同时将校验连接的有效性。默认为false。
      

  5.   

    经查看相关资料,发现问题的原因如下: Mysql服务器默认的“wait_timeout”是8小时,如果connection空闲超过8个小时,Mysql将自动断开该 connection。在C3P0 pools中的connections如果空闲超过8小时,Mysql将其断开,而C3P0中的该connection仍然存在,如果这时有 Client请求connection,C3P0将该断开的Connection提供给Client,将会造成上面的异常。 可以这么解决该问题: 使得Connection pools中connection的lifetime与Mysql的wait_timeout时间达到一致,或者测试Connection pools中connection的有效性。 在wait_timeout的时间为8小时的情况下: C3P0增加以下配置信息: //set to 'SELECT 1' preferredTestQuery = 'SELECT 1' //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 show variables like '%timeout%'; interactive-timeout
      

  6.   


    //是不是设置了cpds.setIdleConnectionTestPeriod(18000);
    TestConnectionOnCheckin ,TestConnectionOnCheckin这俩就可以不设了,实现的效果是一样的