1. 获取资源timeout:

    异常信息如下:

    Caused by: java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.
    [Cause: com.mchange.v2.resourcepool.TimeoutException:
    A client timed out while waiting to acquire a resource from com.mchange.v2.resourcepool.BasicResourcePool@4d5a39b7 -- timeout at awaitAvailable()

    查找发现,获取connection资源timeout的地方,在basicResourcePool类的awaitAvailable方法里,代码很简单:

     private void awaitAvailable(long timeout) throws InterruptedException, TimeoutException, ResourcePoolException
    {
    assert Thread.holdsLock( this ); if (force_kill_acquires)
    throw new ResourcePoolException("A ResourcePool cannot acquire a new resource -- the factory or source appears to be down."); Thread t = Thread.currentThread();
    try
    {
    acquireWaiters.add( t ); int avail;
    long start = ( timeout > 0 ? System.currentTimeMillis() : -1);
    if (Debug.DEBUG && Debug.TRACE == Debug.TRACE_MAX)
    {
    if ( logger.isLoggable( MLevel.FINE ) )
    logger.fine("awaitAvailable(): " +
    (exampleResource != null ?
    exampleResource :
    "[unknown]") );
    trace();
    }
    while ((avail = unused.size()) == 0)
    {
    // the if case below can only occur when 1) a user attempts a
    // checkout which would provoke an acquire; 2) this
    // increments the pending acquires, so we go to the
    // wait below without provoking postAcquireMore(); 3)
    // the resources are acquired; 4) external management
    // of the pool (via for instance unpoolResource()
    // depletes the newly acquired resources before we
    // regain this' monitor; 5) we fall into wait() with
    // no acquires being scheduled, and perhaps a managed.size()
    // of zero, leading to deadlock. This could only occur in
    // fairly pathological situations where the pool is being
    // externally forced to a very low (even zero) size, but
    // since I've seen it, I've fixed it.
    if (pending_acquires == 0 && managed.size() < max)
    _recheckResizePool(); this.wait(timeout);
    if (timeout > 0 && System.currentTimeMillis() - start > timeout)
    throw new TimeoutException("A client timed out while waiting to acquire a resource from " + this + " -- timeout at awaitAvailable()");
    if (force_kill_acquires)
    throw new CannotAcquireResourceException("A ResourcePool could not acquire a resource from its primary factory or source.");
    ensureNotBroken();
    }
    }
    finally
    {
    acquireWaiters.remove( t );
    if (acquireWaiters.size() == 0)
    this.notifyAll();
    }
    }

    抛出异常的是第44行,而抛出异常的先决条件就是timeout了。表象来看是这样,再继续跟进代码的时候发现,进入等待资源的先决条件是:

    1、available==0(unused==0)
    2、managed。size>=max(池数量已达到最大)
    3、获取到的资源异常:如果设置了checkedoutTest这一项时,进行test的时候失败,导致异常;

    所以更直接的原因是以下几种:

    1、请求资源的队列太长,排队时间太长导致超时:线程数量应付不过来大量的请求数量,导致超时
    2、testConnection的原因导致的异常:网络震荡
    3、数据库服务器端无更多的链接可用

    那么相应的解决方案:

    1、请求资源过长的,加大maxsize,如果请求量过大的,尽量将min和max设置成一个值,因此不存在shrink和expand的操作,这也是一种性能消耗
    2、testConnection设置在checkin即可,checkout时无需test,否则卡在网络震荡就不好了
    3、检查数据库端的最大链接数。
    4、将c3p0的debug日志打开,检查它的managed、unused、available的分别size
  2. deadlock  

c3p0--常见异常的更多相关文章

  1. orcal 数据库 maven架构 ssh框架 的全xml环境模版 及常见异常解决

    创建maven项目后,毫不犹豫,超简单傻瓜式搞定dependencies(pom.xml 就是maven的依赖管理),这样你就有了所有你要的包 <project xmlns="http ...

  2. salesforce 零基础学习(五十四)常见异常友好消息提示

    异常或者error code汇总:https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_con ...

  3. 【转】Hibernate 常见异常

    转载地址:http://smartan.iteye.com/blog/1542137 Hibernate 常见异常net.sf.hibernate.MappingException        当出 ...

  4. Spring10种常见异常解决方法

    在程序员生涯当中,提到最多的应该就是SSH三大框架了.作为第一大框架的Spring框架,我们经常使用. 然而在使用过程中,遇到过很多的常见异常,我在这里总结一下,大家共勉. 一.找不到配置文件的异常 ...

  5. Hibernate 常见异常

    Hibernate 常见异常net.sf.hibernate.MappingException        当出现net.sf.hibernate.MappingException: Error r ...

  6. 开通博客第一天 (先发一些android(java)常见异常信息

    常见异常: java.lang.AbstractMethodError抽象方法错误.当应用试图调用抽象方法时抛出. java.lang.AssertionError断言错.用来指示一个断言失败的情况. ...

  7. iOS常见异常Exec_Bad_Access问题解决办法

    iOS常见异常Exec_Bad_Access问题解决办法     在iOS开发中,经常遇到Exec_Bad_Access异常,导致程序奔溃问题,一般这个问题都是因为过早的release对象,然后又对该 ...

  8. 大数据平台常见异常-zookeeper

    本文主要阐述大数据平台环境zookeeper常见异常和解决方案 1.Connection reset by peer异常 异常说明 我们现在项目有个任务OneMinuteDataSync是用spark ...

  9. struts2.1.8+hibernate2.5.6+spring3.0(ssh2三大框架)常见异常原因和解决方案

    ---------------------------------------------------------------------------------------------------- ...

  10. spring集成Junit做单元测试及常见异常解决办法

    spring-test依赖包 <!--Spring-test --> <!-- https://mvnrepository.com/artifact/org.springframew ...

随机推荐

  1. 使用libssh2连接到远程服务器

    libssh2-1.7.0.tar.gz  示例代码:libssh2-1.7.0.tar.gz\libssh2-1.7.0\example 官网示例 https://www.libssh2.org/e ...

  2. Codeforces Round #474-E(树形dp)

    一.题目链接 http://codeforces.com/contest/960/problem/B 二.题意 给定一棵$N$个节点的树,每个节点的权值$V$.定义树中两点$u_1$和$u_m$的权值 ...

  3. 《Linux内核精髓:精通Linux内核必会的75个绝技》一HACK #2 如何编译Linux内核

    HACK #2 如何编译Linux内核 本节介绍编译Linux内核的方法.当发现bug而修改源代码或者添加新功能时,就需要对内核进行重新编译,生成二进制映像文件.另外,如果想要使用发布版内核中无效的功 ...

  4. mysql迁移之巨大数据量快速迁移方案

    mysql迁移之巨大数据量快速迁移方案-增量备份及恢复 --chenjianwen 一.前言: 当mysql库的大小达到几十个G或者上百G,迁移起来是一件非常费事的事情,业务中断,导出导入耗费大量的时 ...

  5. JavaScript Promise的学习笔记

    首先声明:本人今天刚接触Promise,通过一个例子,希望能更好的来理解,如果有不对的地方,还望指正 Promise是专门为解决 js中回调而引起的各种问题,而产生的. 在异步编程中,我们经常使用回调 ...

  6. Shell 函数库

    1.为什么要定义函数库 经常使用的重复代码封装成函数文件 一般不直接执行,而是由其他脚本调用 2.编写一个函数库,该函数库实现以下几个函数. 1.加法函数:add 2.减法函数:reduce 3.乘法 ...

  7. ES6系列_10之Symbol在对象中的作用

    在ES5中 对象属性名都是字符串,这容易造成属性名的冲突,比如,你使用了一个他人提供的对象,但又想为这个对象添加新的方法(mixin 模式),新方法的名字就有可能与现有方法产生冲突,于是 ES6 引入 ...

  8. Pthreads Hello World,忙等待,互斥量

    ▶ 一个简单的 Pthreads 程序(不按照<并行程序设计导论>中的程序来写) ● 代码 #include <stdio.h> #include <pthread.h& ...

  9. Firemonkey MultiView

    MultiView 做导航用的. http://docwiki.embarcadero.com/RADStudio/Seattle/en/Mobile_Tutorial:_Using_a_MultiV ...

  10. Spring IO Platform介绍

    为什么要用Spring IO Platform 今天无意间看到了一个关键词:"Spring IO Platform",第一直觉是不是有关于IO方面的框架或者包呢,查了一下,居然是为 ...