PooledDataSource(ComboPooledDataSource,PoolBackedDataSource) 用户使用的DataSource
C3P0PooledConnectionPoolManager(简称PoolManager)含多个auth(username+password)对应的Pool,基本上用的都是默认auth
C3P0PooledConnectionPool(简称Pool)
ResourcePool(BasicResourcePool,ResourcePoolFactory): 核心接口,所有对其内部状态的访问都需要加锁(其本身),比如用户线程的获取归还,异步线程池的创建移除连接,Timer线程定时的过期检查和空闲检查
Manager(PooledConnectionResourcePoolManager): acquire/destroy, checkin和checkout的处理
ConnectionPoolDataSource(WrapperConnectionPoolDataSource): 获取PooledConnection(对底层连接封装,NewPooledConnection,早期版本存在C3P0PooledConnection通过动态代理实现)
DataSource(DriverManagerDataSource):Driver获取连接
BasicResourcePool:
min max start inc(acquireIncrement,一次获取的增量) unused(池内的) managed(池内+借出的)
过期检查:CullTask定期检查或者checkout了一个资源再检查,根据如下属性
max_resource_age
max_idle_time
excess_max_idle_time(需要考虑min)
destroy_unreturned_resc_time
空闲检查:CheckIdleResourcesTask 定时(check_idle_resources_delay)对所有空闲(unused)资源检查可用性,检查时放入idleCheckResources,检查完后再移除
池大小调整(多处发生): 将池大小(managed)调整到target_pool_size,异步提交多个AcquireTask/RemoveTask
Connection(底层连接)NewPooledConnection(连接池内部使用) NewProxyConnection(用户使用)