zoukankan      html  css  js  c++  java
  • C3P0连接池配置

    C3P0是一个开源的JDBC连接池。

    在Spring中,C3P0的一些配置,介绍如下(只列了一部分,不是全部)

    [html] view plain copy
     
    1. <!-- c3p0连接池配置 -->  
    2.      <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">  
    3.           <!-- 用户名-->  
    4.           <property name="user" value="${username}"/>  
    5.           <!-- 用户密码-->  
    6.           <property name="password" value="${password}"/>  
    7.           <property name="driverClass" value="${driver_class}"/>  
    8.           <property name="jdbcUrl" value="${url}"/>  
    9.   
    10.            <!--连接池中保留的最大连接数。默认值: 15 -->   
    11.           <property name="maxPoolSize" value="20"/>  
    12.           <!-- 连接池中保留的最小连接数,默认为:3-->  
    13.           <property name="minPoolSize" value="2"/>  
    14.           <!-- 初始化连接池中的连接数,取值应在minPoolSize与maxPoolSize之间,默认为3-->  
    15.           <property name="initialPoolSize" value="2"/>  
    16.   
    17.           <!--最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。默认值: 0 -->   
    18.           <property name="maxIdleTime">60</property>  
    19.             
    20.           <!-- 当连接池连接耗尽时,客户端调用getConnection()后等待获取新连接的时间,超时后将抛出SQLException,如设为0则无限期等待。单位毫秒。默认: 0 -->   
    21.           <property name="checkoutTimeout" value="3000"/>  
    22.             
    23.           <!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。默认值: 3 -->   
    24.           <property name="acquireIncrement" value="2"/>  
    25.   
    26.          <!--定义在从数据库获取新连接失败后重复尝试的次数。默认值: 30 ;小于等于0表示无限次-->   
    27.           <property name="acquireRetryAttempts" value="0"/>  
    28.   
    29.           <!--重新尝试的时间间隔,默认为:1000毫秒-->   
    30.           <property name="acquireRetryDelay" value="1000" />  
    31.   
    32.           <!--关闭连接时,是否提交未提交的事务,默认为false,即关闭连接,回滚未提交的事务 -->   
    33.           <property name="autoCommitOnClose">false</property>  
    34.   
    35.           <!--c3p0将建一张名为Test的空表,并使用其自带的查询语句进行测试。如果定义了这个参数那么属性preferredTestQuery将被忽略。你不能在这张Test表上进行任何操作,它将只供c3p0测试使用。默认值: null -->   
    36.           <property name="automaticTestTable">Test</property>  
    37.   
    38.           <!--如果为false,则获取连接失败将会引起所有等待连接池来获取连接的线程抛出异常,但是数据源仍有效保留,并在下次调用getConnection()的时候继续尝试获取连接。如果设为true,那么在尝试获取连接失败后该数据源将申明已断开并永久关闭。默认: false-->   
    39.           <property name="breakAfterAcquireFailure">false</property>  
    40.   
    41.           <!--每60秒检查所有连接池中的空闲连接。默认值: 0,不检查 -->   
    42.           <property name="idleConnectionTestPeriod">60</property>  
    43.           <!--c3p0全局的PreparedStatements缓存的大小。如果maxStatements与maxStatementsPerConnection均为0,则缓存不生效,只要有一个不为0,则语句的缓存就能生效。如果默认值: 0-->   
    44.           <property name="maxStatements">100</property>  
    45.           <!--maxStatementsPerConnection定义了连接池内单个连接所拥有的最大缓存statements数。默认值: 0 -->   
    46.           <property name="maxStatementsPerConnection"></property>  
    47.      </bean>  

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

    C3P0更详细的配置项及其含义,请参考:http://www.mchange.com/projects/c3p0/index.html,部分内容摘录如下:

    acquireIncrement
    acquireRetryAttempts
    acquireRetryDelay
    autoCommitOnClose
    automaticTestTable
    breakAfterAcquireFailure
    checkoutTimeout
    connectionCustomizerClassName
    connectionTesterClassName
    debugUnreturnedConnectionStackTraces
    factoryClassLocation
    forceIgnoreUnresolvedTransactions
    idleConnectionTestPeriod
    initialPoolSize
    maxAdministrativeTaskTime
    maxConnectionAge
    maxIdleTime
    maxIdleTimeExcessConnections
    maxPoolSize
    maxStatements
    maxStatementsPerConnection
    minPoolSize
  • 相关阅读:
    Google验证码Kaptcha的详细过程
    stm32—单总线(1-wire)
    stm32—I2C
    归并排序(MergeSort)
    冒泡排序(Bubble Sort)
    stm32—GPIO
    stm32—时钟系统
    stm32—复位
    转义字符表
    ASCII码表格
  • 原文地址:https://www.cnblogs.com/hoobey/p/5947067.html
Copyright © 2011-2022 走看看