Java开源数据库连接池

Java开源连接池:
Jakarta DBCP 可直接在应用程序中使用。(比较常用,集成在Tomcat和Struts中)
C3P0是Hibernate的默认数据库连接池。(常用,Hibernate)
其他的还有Proxool、DDConnectionBroker、DBPool、XAPool、Primrose、SmartPool、MiniConnectionPoolManager, BoneCP

 

Java6.0自带数据库连接池,从dbcp移至到不同的包下 tomcat-dbcp.jar

The configuration properties for Tomcat's standard data source resource factory (org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory) are as follows: 

driverClassName - Fully qualified Java class name of the JDBC driver to be used.
maxActive - The maximum number of active instances that can be allocated from this pool at the same time.  最大激活连接数,取值为20,表示同时最多有20个数据库连接。
maxIdle - The maximum number of connections that can sit idle in this pool at the same time.

     最大的空闲连接数,这里取值为20,表示即使没有数据库连接时依然可以保持20空闲的连接,而不被清除,随时处于待命状态。
maxWait - The maximum number of milliseconds that the pool will wait (when there are no available connections) for a connection to be returned before throwing an exception.

   最大等待秒钟数,这里取值-1,表示无限等待,直到超时为止,也可取值9000,表示9秒后超时
password - Database password to be passed to our JDBC driver.
url - Connection URL to be passed to our JDBC driver. (For backwards compatibility, the property driverName is also recognized.)
username - Database username to be passed to our JDBC driver.
validationQuery - SQL query that can be used by the pool to validate connections before they are returned to the application. If specified, this query MUST be an SQL SELECT

statement that returns at least one row.

 

 

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
  <property name="driverClass" value="com.mysql.jdbc.Driver" />
  <property name="jdbcUrl" value="${jdbc_url}" />
  <property name="user" value="${jdbc_user}" />
  <property name="password" value="${jdbc_password}" />
  <property name="minPoolSize" value="5" />                    <!--连接池中保留的最小连接数。-->
  <property name="maxPoolSize" value="30" />                   <!--连接池中保留的最大连接数。 Default: 15 -->
  <property name="initialPoolSize" value="10" />               <!--初始化时获取的连接数,取值应在 minPoolSize与maxPoolSize之间。Default: 3 -->
  <property name="maxIdleTime" value="60" />                   <!--最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->
  <property name="acquireIncrement" value="5" />               <!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->
  <property name="maxStatements" value="0" />                  <!--JDBC的标准参数,用以控制数据源内加载的PreparedStatements数量。但由于预缓存的statements属于单个

connection而不是整个连接池。所以设置这个参数需要考虑到多方面的因素。如果maxStatements与 maxStatementsPerConnection均为0,则缓存被关闭。Default: 0-->
  <property name="idleConnectionTestPeriod" value="60" />      <!--每60秒检查所有连接池中的空闲连接。 Default: 0 -->
  <property name="acquireRetryAttempts" value="30" />          <!--定义在从数据库获取新连接失败后重复尝试的次数。Default: 30 -->
  <property name="breakAfterAcquireFailure" value="true" />    <!--获取连接失败将会引起所有等待连接池来获取连接的线程抛出异常。但是数据源仍有效保留,并在下次调用

getConnection()的时候继续尝试获取连接。如果设为true,那么在尝试获取连接失败后该数据源将申明已断开并永久关闭。Default: false-->
  <property name="testConnectionOnCheckout" value="false" />   <!--因性能消耗大请只在需要的时候使用它。如果设为true那么在每个connection提交的时候都将校验其有效性。

建议使用idleConnectionTestPeriod或automaticTestTable等方法来提升连接测试的性能。Default: false -->
 </bean>

 


关注: http://jolbox.com/  BoneCP


两者对比:
<resource-ref>--资源引用,一般声明管理资源,如数据库驱动程序、JavaMail Session、自定义类工厂等。
<resource-env-ref>--资源环境引用,在Servlet 2.4里用来简化设置不需认证信息的资源环境,一般声明与资源相关的被管理对象,如环境参数、resource-ref变量。

 

 

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值