`
haouziwefe
  • 浏览: 128018 次
  • 性别: Icon_minigender_2
  • 来自: 杭州
社区版块
存档分类
最新评论
阅读更多

   
    <h1 style="text-align: center; margin: 17pt 0cm 16.5pt;">[size=x-large;]<span style="" lang="EN-US"><span style="font-family: Times New Roman;">Java[/size]</span><span style="">框架数据库连接池比较(</span><span style="" lang="EN-US"><span style="font-family: Times New Roman;">c3p0,dbcp</span></span><span style="">和</span><span style="" lang="EN-US"><span style="font-family: Times New Roman;">proxool</span></span><span style="">)</span><span style="" lang="EN-US"></span></span></h1>
<table class="MsoNormalTable" style="width: 100%; border-collapse: collapse;" border="0" cellspacing="0" cellpadding="0" width="100%"><tbody><tr style="">
<td style="background-color: transparent; border: #d4d0c8; padding: 0.75pt;">

<h2 style="margin: 13pt 0cm;"><span style="" lang="EN-US">[size=large;]<span style="font-family: Arial;">1. Apache-DBCP [/size]</span></span></h2>
<p class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt;" align="left"><span style="" lang="EN-US">? BasicDataSource </span><span style="">相关的参数说明<span lang="EN-US"> <br>dataSource: </span>要连接的<span lang="EN-US"> datasource (</span>通常我们不会定义在<span lang="EN-US"> server.xml) <br>defaultAutoCommit: </span>对于事务是否<span lang="EN-US"> autoCommit, </span>默认值为<span lang="EN-US"> true <br>defaultReadOnly: </span>对于数据库是否只能读取<span lang="EN-US">, </span>默认值为<span lang="EN-US"> false <br>driverClassName:</span>连接数据库所用的<span lang="EN-US"> JDBC Driver Class, <br>maxActive: </span>可以从对象池中取出的对象最大个数,为<span lang="EN-US">0</span>则表示没有限制,默认为<span lang="EN-US">8 <br>maxIdle: </span>最大等待连接中的数量<span lang="EN-US">,</span>设<span lang="EN-US"> 0 </span>为没有限制 (对象池中对象最大个数)<span lang="EN-US"> <br>minIdle</span>:对象池中对象最小个数<span lang="EN-US"> <br>maxWait: </span>最大等待秒数<span lang="EN-US">, </span>单位为<span lang="EN-US"> ms, </span>超过时间会丟出错误信息<span lang="EN-US"> <br>password: </span>登陆数据库所用的密码<span lang="EN-US"> <br>url: </span>连接数据库的<span lang="EN-US"> URL <br>username: </span>登陆数据库所用的帐号<span lang="EN-US"> <br>validationQuery: </span>验证连接是否成功<span lang="EN-US">, SQL SELECT </span>指令至少要返回一行<span lang="EN-US"> <br>removeAbandoned: </span>是否自我中断<span lang="EN-US">, </span>默认是<span lang="EN-US"> false <br>removeAbandonedTimeout: </span>几秒后会自我中断<span lang="EN-US">, removeAbandoned </span>必须为<span lang="EN-US"> true <br>logAbandoned: </span>是否记录中断事件<span lang="EN-US">, </span>默认为<span lang="EN-US"> false <br>minEvictableIdleTimeMillis</span>:大于<span lang="EN-US">0 </span>,进行连接空闲时间判断,或为<span lang="EN-US">0</span>,对空闲的连接不进行验证;默认<span lang="EN-US">30</span>分钟<span lang="EN-US"> <br>timeBetweenEvictionRunsMillis</span>:失效检查线程运行时间间隔,如果小于等于<span lang="EN-US">0</span>,不会启动检查线程,默认<span lang="EN-US">-1 <br>testOnBorrow</span>:取得对象时是否进行验证,检查对象是否有效,默认为<span lang="EN-US">false <br>testOnReturn</span>:返回对象时是否进行验证,检查对象是否有效,默认为<span lang="EN-US">false <br>testWhileIdle</span>:空闲时是否进行验证,检查对象是否有效,默认为<span lang="EN-US">false <br>? </span>在使用<span lang="EN-US">DBCP</span>的时候,如果使用默认值,则数据库连接因为某种原因断掉后,再从连接池中取得连接又不进行验证,这时取得的连接实际上就会是无效的数据库连接。因此为了防止获得的数据库连接失效,在使用的时候最好保证:<span lang="EN-US"> <br>username: </span>登陆数据库所用的帐号<span lang="EN-US"> <br>validationQuery</span>:<span lang="EN-US">SELECT COUNT(*) FROM DUAL <br>testOnBorrow</span>、<span lang="EN-US">testOnReturn</span>、<span lang="EN-US">testWhileIdle</span>:最好都设为<span lang="EN-US">true <br>minEvictableIdleTimeMillis</span>:大于<span lang="EN-US">0 </span>,进行连接空闲时间判断,或为<span lang="EN-US">0</span>,对空闲的连接不进行验证<span lang="EN-US"> <br>timeBetweenEvictionRunsMillis</span>:失效检查线程运行时间间隔,如果小于等于<span lang="EN-US">0</span>,不会启动检查线程<span lang="EN-US"> <br>? PS:</span>在构造<span lang="EN-US">GenericObjectPool [BasicDataSource</span>在其<span lang="EN-US">createDataSource () </span>方法中也会使用<span lang="EN-US">GenericObjectPool] </span>时,会生成一个内嵌类<span lang="EN-US">Evictor</span>,实现自<span lang="EN-US">Runnable</span>接口。如果<span lang="EN-US">timeBetweenEvictionRunsMillis</span>大于<span lang="EN-US">0</span>,每过<span lang="EN-US">timeBetweenEvictionRunsMillis</span>毫秒<span lang="EN-US">Evictor</span>会调用<span lang="EN-US">evict()</span>方法,检查对象的闲置时间是否大于<span lang="EN-US"> minEvictableIdleTimeMillis</span>毫秒(<span lang="EN-US">_minEvictableIdleTimeMillis</span>小于等于<span lang="EN-US">0</span>时则忽略,默认为<span lang="EN-US">30</span>分钟),是则销毁此对象,否则就激活并校验对象,然后调用<span lang="EN-US">ensureMinIdle</span>方法检查确保池中对象个数不小于<span lang="EN-US">_minIdle</span>。在调用<span lang="EN-US">returnObject</span>方法把对象放回对象池,首先检查该对象是否有效,然后调用<span lang="EN-US">PoolableObjectFactory </span>的<span lang="EN-US">passivateObject</span>方法使对象处于非活动状态。再检查对象池中对象个数是否小于<span lang="EN-US">maxIdle</span>,是则可以把此对象放回对象池,否则销毁此对象<span lang="EN-US"> <br>? </span>上述特性的可设置性已在代码中验证,具体性能是否能实现有待实际验证 <span lang="EN-US"></span></span>

<p class="MsoNormal" style="text-align: left; line-height: 10.95pt; margin: 0cm 0cm 0pt; background: white;" align="left">[size=x-small;]<span style="" lang="EN-US">?<Resource name="lda/raw"<br>????????????? type="javax.sql.DataSource"<br>?????????????? password="lda_master"<br>?????????????? driverClassName="oracle.jdbc.driver.OracleDriver"<br>?????????????? maxIdle="30" minIdle="2" maxWait="60000" maxActive="1000"[/size]<span style="" lang="EN-US">?</span></span><span style="" lang="EN-US"><br>[size=x-small;]?????????????? testOnBorrow="true" testWhileIdle="true" validationQuery="select 1 from dual"<br>?????????????? username="lda_master" url="jdbc:oracle:thin:@192.160.100.107:15537:lcststd"/>[/size]</span>

<p class="MsoNormal" style="text-align: left; line-height: 10.95pt; margin: 0cm 0cm 0pt; background: white;" align="left">[size=x-small;]<span style="">这样一来,就能够解决[/size]<span style="" lang="EN-US">Connect Reset</span><span style="">的问题了。刚才说了,其实很多</span><span style="" lang="EN-US">App Server</span><span style="">都会有相应的配置地方,只是大型的服务器正好提供了</span><span style="" lang="EN-US">Admin Console</span><span style="">,上面可以显式的配置</span><span style="" lang="EN-US">Connection Pool</span><span style="">,也有明显的属性选择,这里就不一一详述了,都是眼见的功夫。</span><span style="" lang="EN-US"></span></span>

<p class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt;" align="left"><span style="" lang="EN-US">?</span>
<h2 style="margin: 13pt 0cm;"><span style="" lang="EN-US">[size=large;]<span style="font-family: Arial;">3. Proxool [/size]</span></span></h2>

<p class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt;" align="left"><span style="" lang="EN-US">?</span>
</td>
</tr></tbody></table>

<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-family: Times New Roman; font-size: small;">?</span></span>

<h1 style="text-align: center; margin: 17pt 0cm 16.5pt;">[size=x-large;]<span style="">总结[/size]<span lang="EN-US"><span style="font-family: Times New Roman;">spring</span></span><span style="">下配置</span><span lang="EN-US"><span style="font-family: Times New Roman;">dbcp,c3p0,proxool</span></span><span style="">数据源链接池</span></span></h1>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-family: Times New Roman; font-size: small;">?</span></span>

<p class="MsoNormal" style="line-height: 17.25pt; margin: 0cm 0cm 0pt; background: white;"><span style=""><span style="color: #666666; font-size: 10pt;" lang="EN-US"><span style="font-family: Times New Roman;"><?xml version="1.0" encoding="UTF-8"?></span></span></span>

<p class="MsoNormal" style="line-height: 17.25pt; margin: 0cm 0cm 0pt; background: white;"><span style=""><span style="color: #666666; font-size: 10pt;" lang="EN-US"><span style="font-family: Times New Roman;"><beans default-autowire="no" default-lazy-init="true"<br>default-dependency-check="none"><br><description>datasource</description><br><!-- ???<br><bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"><br>?? <property name="driverClassName"><value>${jdbc.driverClassName}</value></property><br>?? <property name="url"><value>${jdbc.url}</value></property><br>?? <property name="username"><value>${jdbc.username}</value></property><br>?? <property name="password"><value>${jdbc.password}</value></property><br></bean><br>--></span></span></span>

<p class="MsoNormal" style="line-height: 17.25pt; margin: 0cm 0cm 0pt; background: white;"><span style=""><span style="color: #666666; font-size: 10pt;" lang="EN-US"><span style="font-family: Times New Roman;"><!--bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"><br>??????? <property name="driverClass"><value>${jdbc.driverClassName}</value></property><br>??????? <property name="jdbcUrl"><value>${jdbc.url}</value></property><br>??????? <property name="user"><value>${jdbc.username}</value></property><br>??????? <property name="password"><value>${jdbc.password}</value></property>??<br>??????? <property name="acquireIncrement"><value>5</value></property><br>??????? <property name="idleConnectionTestPeriod"><value>3000</value></property><br>??????? <property name="checkoutTimeout"><value>3000</value></property><br>??????? <property name="maxPoolSize"><value>80</value></property><br>??????? <property name="minPoolSize"><value>1</value></property><br>??????? <property name="maxStatements"><value>6000</value></property><br>??????? <property name="initialPoolSize"><value>5</value></property><br></bean--><br><br><!--<br>ComboPooledDataSource </span></span></span><span style=""><span style="">参数说明</span></span>

<p class="MsoNormal" style="line-height: 17.25pt; margin: 0cm 0cm 0pt; background: white;"><span style=""><span style="color: #666666; font-size: 10pt;" lang="EN-US"><span style="font-family: Times New Roman;"><!--bean id="dataSource" class="org.logicalcobwebs.proxool.ProxoolDataSource"><br>?? <property name="driver"><value>${jdbc.driverClassName}</value></property><br>?? <property name="driverUrl"><value>${jdbc.url}</value></property><br>?? <property name="user"><value>${jdbc.username}</value></property><br>?? <property name="password"><value>${jdbc.password}</value></property><br>?? <property name="alias"><value>test</value></property><br>?? <property name="houseKeepingSleepTime"><value>90000</value></property><br>?? <property name="prototypeCount"><value>10</value></property><br>?? <property name="maximumConnectionCount"><value>100</value></property><br>?? <property name="minimumConnectionCount"><value>10</value></property><br>?? <property name="trace"><value>true</value></property><br>?? <property name="verbose"><value>true</value></property><br></bean><br>--></span></span></span>

<p class="MsoNormal" style="line-height: 17.25pt; margin: 0cm 0cm 0pt; background: white;"><span style=""><span style="color: #666666; font-size: 10pt;" lang="EN-US"><span style="font-family: Times New Roman;">jdbc.properties</span></span></span>

<p class="MsoNormal" style="line-height: 17.25pt; margin: 0cm 0cm 0pt; background: white;"><span style=""><span style="color: #666666; font-size: 10pt;" lang="EN-US"><br><span style="font-family: Times New Roman;">#jdbc.driverClassName=org.hsqldb.jdbcDriver<br>#jdbc.url=jdbc:hsqldb:file:hsqldb/test<br>#jdbc.username=sa<br>#jdbc.password=</span></span></span>

<p class="MsoNormal" style="line-height: 17.25pt; margin: 0cm 0cm 0pt; background: white;"><span style=""><span style="color: #666666; font-size: 10pt;" lang="EN-US"><span style="font-family: Times New Roman;">#jdbc.url=jdbc:mysql://localhost:3306/test?user=root&amp;amp;amp;password=root&amp;amp;amp;useUnicode=true&amp;amp;amp;characterEncoding=UTF-8&amp;amp;amp;characterSetResults=UTF-8</span></span></span>

<p class="MsoNormal" style="line-height: 17.25pt; margin: 0cm 0cm 0pt; background: white;"><span style=""><span style="color: #666666; font-size: 10pt;" lang="EN-US"><span style="font-family: Times New Roman;">#jndi<br>jndi.factory.initial=weblogic.jndi.WLInitialContextFactory<br>jndi.provider.url=t3://127.0.0.1:7001<br>jndi.jndiName=jdbc/test</span></span></span>

<p class="MsoNormal" style="line-height: 16.75pt; margin: 0cm 0cm 0pt;"><span style=""><span style="color: #666666; font-size: 10pt;" lang="EN-US"><br><span style="font-family: Times New Roman;">#hibernate.dialect=org.hibernate.dialect.SQLServerDialect<br>hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect<br>#hibernate.dialect=org.hibernate.dialect.HSQLDialect<br>hibernate.cache.use_query_cache=true<br>#hibernate.cache.provider_class=net.sf.hibernate.cache.EhCacheProvider<br>hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider<br>hibernate.show_sql=true<br>hibernate.format_sql=false<br>hibernate.transaction.auto_close_session=true<br>hibernate.connection.autocommit=false<br>hibernate.connection.isolation=2<br>hibernate.hbm2ddl.auto=update<br>hibernate.jdbc.fetch_size=50<br>hibernate.jdbc.batch_size=25<br>hibernate.default_batch_fetch_size=16<br>hibernate.transaction.factory_class=org.hibernate.transaction.JDBCTransactionFactory<br>#hibernate.transaction.factory_class=net.sf.hibernate.transaction.JDBCTransactionFactory<br>hibernate.query.factory_class=org.hibernate.hql.classic.ClassicQueryTranslatorFactory<br>hibernate.connection.release_mode=after_transaction<br>hibernate.cache.region_prefix=hibernate.cache.test<br>hibernate.default_schema=test</span></span></span><span style="color: #666666;" lang="EN-US"></span>
<h1 style="text-align: center; margin: 17pt 0cm 16.5pt;">[size=x-large;]<span lang="EN-US"><span style="font-family: Times New Roman;">tomcat[/size]</span><span style="">下配置数据库连接池</span><span lang="EN-US"><span style="font-family: Times New Roman;">DBCP</span></span><span style="">、</span><span lang="EN-US"><span style="font-family: Times New Roman;">C3P0</span></span><span style="">、</span><span lang="EN-US"><span style="font-family: Times New Roman;">Proxool</span></span></span></h1>

<h2 style="margin: 13pt 0cm;">[size=large;]<span lang="EN-US"><span style="font-family: Arial;">1[/size]</span><span style="">、将连接池的</span><span lang="EN-US"><span style="font-family: Arial;">jar</span></span><span style="">文件拷贝到</span><span lang="EN-US"><span style="font-family: Arial;">tomcat</span></span><span style="">的</span><span lang="EN-US"><span style="font-family: Arial;">lib</span></span><span style="">目录下</span></span></h2>
<span lang="EN-US"><span style="">(1)dbcp:</span></span>

[size=small;]<span style=""><span lang="EN-US">tomcat[/size]默认包含<span lang="EN-US">tomcat-dbcp.jar,</span>如果使用<span lang="EN-US">tomcat</span>自带的<span lang="EN-US">dbcp</span>则不用拷贝<span lang="EN-US">jar</span>文件。</span></span>

<span style="">如果要使用<span lang="EN-US">commons-dbcp</span>连接池,则要将<span lang="EN-US">commons-dbcp-xxx.jar</span>和<span lang="EN-US">commons-pool.jar</span>拷贝到<span lang="EN-US">tomcat</span>的<span lang="EN-US">lib</span>目录下。</span>

<span style="">(<span lang="EN-US">2</span>)<span lang="EN-US">c3p0</span>:</span>

<span style="">拷贝<span lang="EN-US">c3p0-xx.jar</span>到<span lang="EN-US">tomcat</span>的<span lang="EN-US">lib</span>目录下</span>

<span style="">(<span lang="EN-US">3</span>)<span lang="EN-US">proxool</span>:</span>

<span style="">拷贝<span lang="EN-US">proxool-xx.jar</span>、<span lang="EN-US">proxool-cglib.jar</span>、<span lang="EN-US">commons-logging-xxx.jar</span>到<span lang="EN-US">tomcat</span>的<span lang="EN-US">lib</span>目录下</span>

<h2 style="margin: 13pt 0cm;">[size=large;]<span lang="EN-US"><span style="font-family: Arial;">2[/size]</span><span style="">、打开</span><span lang="EN-US"><span style="font-family: Arial;">tomcat</span></span><span style="">的</span><span lang="EN-US"><span style="font-family: Arial;">context.xml</span></span><span style="">,进行如下配置:</span></span></h2>
[size=small;]<span style=""><span lang="EN-US"><!--dbcp--><br><Resource <br>??? name="jdbc/mysqlds-dbcp" <br>??? auth="Container" <br>??? type= "javax.sql.DataSource" <br>factory="org.apache.commons.dbcp.BasicDataSourceFactory"<!--[/size]这里使用的<span lang="EN-US">commons-dbcp</span>连接池<span lang="EN-US">--></span></span></span>

[size=small;]<span style=""><span lang="EN-US"><!--tomcat[/size]的<span lang="EN-US">dbcp</span>对应的<span lang="EN-US">factory</span>为:将<span lang="EN-US">commons</span>替换为<span lang="EN-US">tomcat</span>,也可不用配置</span></span><span lang="EN-US"><span style="">--><br>??? driverClassName="com.mysql.jdbc.Driver" <br>??? url="jdbc:mysql://localhost:3306/test"<br>??? username="root" <br>??? password=""<br>??? maxActive="100" <br>??? maxIdle="30"<br>??? maxWait="10000" > <br></Resource> <br>?? <!--c3p0--><br><Resource auth="Container"<br>???? description="DB Connection"<br>???? driverClass="com.mysql.jdbc.Driver"<br>???? maxPoolSize="100"<br>???? minPoolSize="2"<br>???? acquireIncrement="2"<br>???? name="jdbc/mysqlds-c3p0"<br>???? user="root"<br>???? password=""<br>???? factory="org.apache.naming.factory.BeanFactory"<br>???? type="com.mchange.v2.c3p0.ComboPooledDataSource"<br>???? jdbcUrl="jdbc:mysql://localhost:3306/test" /></span></span>

<span lang="EN-US"><span style=""><!--proxool--></span></span>

<span lang="EN-US"><span style=""><Resource name="jdbc/mysqlds-proxool" <br>???? auth="Container"?????? <br>???? type="javax.sql.DataSource" <br>???? factory="org.logicalcobwebs.proxool.ProxoolDataSource"?????? <br>???? proxool.alias="test"?????? <br>???? user="root"???? <br>???? password=""?????? <br>???? delegateProperties="foo=1,bar=true" <br>???? proxool.jndi-name="mysqljndi"????? <br>???? proxool.driver-url="jdbc:mysql://127.0.0.1:3306/test"?????? <br>???? proxool.driver-class="com.mysql.jdbc.Driver"???? <br>???? proxool.house-keeping-sleep-time="900000"???? <br>???? proxool.maximum-active-time="5" <br>???? proxool.prototype-count="3" <br>???? proxool.statistics="1m,15m,1d" <br>???? proxool.simultaneous-build-throttle="10" <br>???? proxool.minimum-connection-count="5" <br>???? proxool.maximum-connection-count="15"??? <br>/>??</span></span>

<h2 style="margin: 13pt 0cm;">[size=large;]<span lang="EN-US"><span style="font-family: Arial;">3[/size]</span><span style="">、在</span><span lang="EN-US"><span style="font-family: Arial;">web.xml</span></span><span style="">中配置如下代码:</span></span></h2>
[size=small;]<span style=""><span lang="EN-US"><resource-ref>?? <br><res-ref-name>jdbc/mysqlds-proxool</res-ref-name>?? <!--[/size]与<span lang="EN-US">context.xml</span>下的<span lang="EN-US">Resources</span>的<span lang="EN-US">name</span>属性一致</span></span><span lang="EN-US"><span style="">--><br><res-type>javax.sql.DataSource</res-type>?? <br><res-auth>Container</res-auth>?? <br></resource-ref></span></span>

<h2 style="margin: 13pt 0cm;">[size=large;]<span lang="EN-US"><span style="font-family: Arial;">4[/size]</span><span style="">、获取连接</span><span lang="EN-US"><span style="font-family: Arial;">java</span></span><span style="">代码:</span></span></h2>
[size=small;]<span style=""><span lang="EN-US">?? Context context = new InitialContext();<br>??? ds = (DataSource) context.lookup("java:/comp/env/jdbc/mysqlds-proxool");//[/size]与<span lang="EN-US">context.xml</span>下的<span lang="EN-US">Resources</span>的<span lang="EN-US">name</span>属性一致</span></span>

<h2 style="margin: 13pt 0cm;">[size=large;]<span lang="EN-US"><span style="font-family: Arial;">5[/size]</span><span style="">、常见问题:</span></span></h2>
<span style="">[size=small;]<span lang="EN-US">????? [/size](<span lang="EN-US">1</span>)<span lang="EN-US">create a new connection but it fail its test:</span></span></span>

<span style="">[size=small;]<span lang="EN-US">?????? [/size]在配置<span lang="EN-US">proxool</span>连接池时,可能会包以上错误,可以看看你的<span lang="EN-US">context.xml</span>配置<span lang="EN-US">,</span>将</span></span>

<p class="MsoNormal" style="line-height: 16.75pt; margin: 0cm 0cm 0pt;">[size=small;]<span lang="EN-US"><span style="font-family: Times New Roman;">proxool.test-before-use="true"[/size]</span><span style="">该行去掉即可,即在使用前不要进行测试</span><span style="color: #666666;" lang="EN-US"></span></span>

<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-family: Times New Roman; font-size: small;">?</span></span>
<h1 style="text-align: center; margin: 17pt 0cm 16.5pt;">
<span style="line-height: 240%; font-size: 18pt;" lang="EN-US"><span style="font-family: Times New Roman;">DBCP</span></span><span style="">,</span><span style="line-height: 240%; font-size: 18pt;" lang="EN-US"><span style="font-family: Times New Roman;">C3P0</span></span><span style="">,</span><span style="line-height: 240%; font-size: 18pt;" lang="EN-US"><span style="font-family: Times New Roman;">Proxool</span></span><span style="">,</span><span style="line-height: 240%; font-size: 18pt;" lang="EN-US"><span style="font-family: Times New Roman;">BoneCP</span></span><span style="">参数介绍</span><span style="font-family: Times New Roman; font-size: x-large;"> </span>
</h1>

<h2 style="margin: 13pt 0cm;">[size=large;]<span lang="EN-US"><span style="font-family: Arial;">1 Apache-DBCP[/size]</span><span style="">:</span><span style="font-family: Arial;"> </span></span></h2>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;">[size=small;]<span lang="EN-US"><span style="font-family: Times New Roman;">dataSource: [/size]</span><span style="">要连接的</span><span lang="EN-US"><span style="font-family: Times New Roman;"> datasource (</span></span><span style="">通常我们不会定义在</span></span>[size=small;]<span lang="EN-US"><span style="font-family: Times New Roman;"> server.xml) <br>defaultAutoCommit: [/size]</span><span style="">对于事务是否</span><span lang="EN-US"><span style="font-family: Times New Roman;"> autoCommit, </span></span><span style="">默认值为</span></span>[size=small;]<span lang="EN-US"><span style="font-family: Times New Roman;"> true <br>defaultReadOnly: [/size]</span><span style="">对于数据库是否只能读取</span><span lang="EN-US"><span style="font-family: Times New Roman;">, </span></span><span style="">默认值为</span></span>[size=small;]<span lang="EN-US"><span style="font-family: Times New Roman;"> false <br>driverClassName:[/size]</span><span style="">连接数据库所用的</span></span>[size=small;]<span lang="EN-US"><span style="font-family: Times New Roman;"> JDBC Driver Class, <br>maxActive: [/size]</span><span style="">可以从对象池中取出的对象最大个数,为</span><span lang="EN-US"><span style="font-family: Times New Roman;">0</span></span><span style="">则表示没有限制,默认为</span></span>[size=small;]<span lang="EN-US"><span style="font-family: Times New Roman;">8 <br>maxIdle: [/size]</span><span style="">最大等待连接中的数量</span><span lang="EN-US"><span style="font-family: Times New Roman;">,</span></span><span style="">设</span><span lang="EN-US"><span style="font-family: Times New Roman;"> 0 </span></span><span style="">为没有限制</span><span style="font-family: Times New Roman;"> </span><span style="">(对象池中对象最大个数)</span></span>[size=small;]<span lang="EN-US"><span style="font-family: Times New Roman;"> <br>minIdle[/size]</span><span style="">:对象池中对象最小个数</span></span>[size=small;]<span lang="EN-US"><span style="font-family: Times New Roman;"> <br>maxWait: [/size]</span><span style="">最大等待秒数</span><span lang="EN-US"><span style="font-family: Times New Roman;">, </span></span><span style="">单位为</span><span lang="EN-US"><span style="font-family: Times New Roman;"> ms, </span></span><span style="">超过时间会丟出错误信息</span></span>[size=small;]<span lang="EN-US"><span style="font-family: Times New Roman;"> <br>password: [/size]</span><span style="">登陆数据库所用的密码</span></span>[size=small;]<span lang="EN-US"><span style="font-family: Times New Roman;"> <br>url: [/size]</span><span style="">连接数据库的</span></span>[size=small;]<span lang="EN-US"><span style="font-family: Times New Roman;"> URL <br>username: [/size]</span><span style="">登陆数据库所用的帐号</span></span>[size=small;]<span lang="EN-US"><span style="font-family: Times New Roman;"> <br>validationQuery: [/size]</span><span style="">验证连接是否成功</span><span lang="EN-US"><span style="font-family: Times New Roman;">, SQL SELECT </span></span><span style="">指令至少要返回一行</span></span>[size=small;]<span lang="EN-US"><span style="font-family: Times New Roman;"> <br>removeAbandoned: [/size]</span><span style="">是否自我中断</span><span lang="EN-US"><span style="font-family: Times New Roman;">, </span></span><span style="">默认是</span></span>[size=small;]<span lang="EN-US"><span style="font-family: Times New Roman;"> false <br>removeAbandonedTimeout: [/size]</span><span style="">几秒后会自我中断</span><span lang="EN-US"><span style="font-family: Times New Roman;">, removeAbandoned </span></span><span style="">必须为</span></span>[size=small;]<span lang="EN-US"><span style="font-family: Times New Roman;"> true <br>logAbandoned: [/size]</span><span style="">是否记录中断事件</span><span lang="EN-US"><span style="font-family: Times New Roman;">, </span></span><span style="">默认为</span></span>[size=small;]<span lang="EN-US"><span style="font-family: Times New Roman;"> false <br>minEvictableIdleTimeMillis[/size]</span><span style="">:大于</span><span lang="EN-US"><span style="font-family: Times New Roman;">0 </span></span><span style="">,进行连接空闲时间判断,或为</span><span lang="EN-US"><span style="font-family: Times New Roman;">0</span></span><span style="">,对空闲的连接不进行验证;默认</span><span lang="EN-US"><span style="font-family: Times New Roman;">30</span></span><span style="">分钟</span></span>[size=small;]<span lang="EN-US"><span style="font-family: Times New Roman;"> <br>timeBetweenEvictionRunsMillis[/size]</span><span style="">:失效检查线程运行时间间隔,如果小于等于</span><span lang="EN-US"><span style="font-family: Times New Roman;">0</span></span><span style="">,不会启动检查线程,默认</span></span>[size=small;]<span lang="EN-US"><span style="font-family: Times New Roman;">-1 <br>testOnBorrow[/size]</span><span style="">:取得对象时是否进行验证,检查对象是否有效,默认为</span></span>[size=small;]<span lang="EN-US"><span style="font-family: Times New Roman;">false <br>testOnReturn[/size]</span><span style="">:返回对象时是否进行验证,检查对象是否有效,默认为</span></span>[size=small;]<span lang="EN-US"><span style="font-family: Times New Roman;">false <br>testWhileIdle[/size]</span><span style="">:空闲时是否进行验证,检查对象是否有效,默认为</span></span>[size=small;]<span lang="EN-US"><span style="font-family: Times New Roman;">false <br>initialSize[/size]</span><span style="">:初始化线程数</span><span style="font-family: Times New Roman;"> </span></span>

<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-family: Times New Roman; font-size: small;">?</span></span>
<h2 style="margin: 13pt 0cm;">[size=large;]<span style="font-family: Arial;"><span lang="EN-US">2 C[/size]<span lang="EN-US">3P0</span></span><span style="">:</span><span style="font-family: Arial;"> </span></span></h2>

<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-family: Times New Roman; font-size: small;">?</span></span>

<h2 style="margin: 13pt 0cm;">[size=large;]<span lang="EN-US"><span style="font-family: Arial;">3 Proxool[/size]</span><span style="">:</span></span></h2>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-family: Times New Roman; font-size: small;">?</span></span>

<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-family: Times New Roman; font-size: small;">?</span></span>

<h2 style="margin: 13pt 0cm;">[size=large;]<span lang="EN-US"><span style="font-family: Arial;">4 BoneCP[/size]</span><span style="">:</span><span style="font-family: Arial;"> </span></span></h2>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-family: Times New Roman; font-size: small;">?</span></span>

<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-family: Times New Roman; font-size: small;">?</span></span>

<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="" lang="EN-US"><property</span><span style="" lang="EN-US"> </span><span style="" lang="EN-US">name="driverClass"</span><span style="" lang="EN-US"> </span><span style="" lang="EN-US">value="com.mysql.jdbc.Driver"</span><span style="" lang="EN-US"> </span><span style="" lang="EN-US">/></span>

<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="" lang="EN-US"><property</span><span style="" lang="EN-US"> </span><span style="" lang="EN-US">name="username"</span><span style="" lang="EN-US"> </span><span style="" lang="EN-US">value="root"/></span>

<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="" lang="EN-US"><property</span><span style="" lang="EN-US"> </span><span style="" lang="EN-US">name="idleConnectionTestPeriod"</span><span style="" lang="EN-US"> </span><span style="" lang="EN-US">value="60"/></span>

<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="" lang="EN-US"><property</span><span style="" lang="EN-US"> </span><span style="" lang="EN-US">name="maxConnectionsPerPartition"</span><span style="" lang="EN-US"> </span><span style="" lang="EN-US">value="30"/></span><span style="" lang="EN-US"></span>

<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="" lang="EN-US"><property</span><span style="" lang="EN-US"> </span><span style="" lang="EN-US">name="partitionCount"</span><span style="" lang="EN-US"> </span><span style="" lang="EN-US">value="3"/></span>

<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="" lang="EN-US"><property</span><span style="" lang="EN-US"> </span><span style="" lang="EN-US">name="statementsCacheSize"</span><span style="" lang="EN-US"> </span><span style="" lang="EN-US">value="100"/></span>

<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="" lang="EN-US"></bean></span><span style="" lang="EN-US"></span>

<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-family: Times New Roman; font-size: small;">?</span></span>
<h1 style="text-align: center; margin: 17pt 0cm 16.5pt;">[size=x-large;]<span style="font-family: Times New Roman;"><span lang="EN-US">1 c[/size]<span lang="EN-US">3p0</span></span><span style="">、</span><span lang="EN-US"><span style="font-family: Times New Roman;">dbcp</span></span><span style="">、</span><span lang="EN-US"><span style="font-family: Times New Roman;">proxool</span></span><span style="">、</span><span lang="EN-US"><span style="font-family: Times New Roman;">BoneCP</span></span><span style="">比较</span></span></h1>
<h2 style="margin: 13pt 0cm;">[size=large;]<span lang="EN-US"><span style="font-family: Arial;">1.1 [/size]</span><span style="">测试环境</span><span lang="EN-US"><span style="font-family: Arial;">:</span></span></span></h2>

<h2 style="margin: 13pt 0cm;">[size=large;]<span lang="EN-US"><span style="font-family: Arial;">1.2 [/size]</span><span style="">测试条件:</span><span style="font-family: Arial;"> </span></span></h2>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;">[size=small;]<span lang="EN-US"><span style="font-family: Times New Roman;">initialSize=30; <br>maxSize=200; <br>minSize=30; <br>[/size]</span><span style="">其余参数为默认值;</span><span style="font-family: Times New Roman;"> </span></span>
<h2 style="margin: 13pt 0cm;">[size=large;]<span lang="EN-US"><span style="font-family: Arial;">1.3 [/size]</span><span style="">测试代码:</span></span></h2>

<h2 style="margin: 13pt 0cm;">[size=large;]<span lang="EN-US"><span style="font-family: Arial;">4.4[/size]</span><span style="">测试结果分析:</span></span></h2>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;">[size=small;]<span lang="EN-US"><span style="font-family: Times New Roman;">???????? BoneCP[/size]</span><span style="">一直保持性能最佳</span><span style="font-family: Times New Roman;"> </span></span>
<h2 style="margin: 13pt 0cm;">[size=large;]<span lang="EN-US"><span style="font-family: Arial;">4.5 [/size]</span><span style="">测试结论</span><span style="font-family: Arial;"> </span></span></h2>

 
 
0
0
分享到:
评论

相关推荐

    JAVA数据库连接池(C3P0,Druid,JNDI ,DBCP,Proxool,BoneCP)

    本文将详细介绍几个常见的Java数据库连接池实现:C3P0、Druid、JNDI、DBCP、Proxool以及BoneCP,并结合Spring+MyBatis+maven环境下的应用示例进行解析。 1. C3P0: C3P0是一个开源的JDBC连接池,它实现了数据源和...

    Spring3中配置DBCP,C3P0,Proxool,Bonecp数据源

    在Spring3中配置数据源,包括DBCP,C3P0,Proxool,Bonecp主要的数据源,里面包含这些数据源的jar文件和依赖文件及配置文件。。 如Bonecp目前听说是最快的数据源,速度是传统的c3p0的25倍, bonecp.properties文件: ...

    数据连接池用法(C3PO,proxool,dbcp,bonecp)

    本文将详细介绍四个常见的Java数据连接池组件——C3PO、Proxool、DBCP和BoneCP的配置与用法。 首先,我们来看C3PO(Comprehensive3rdPartyPooling),这是一个基于Apache Commons DBCP的数据库连接池实现,具有更好...

    几种数据库连接池详细配置

    本文将深入解析几种常用的数据库连接池——Apache DBCP、C3P0、Proxool、BoneCP的详细配置参数,帮助开发者更好地理解和应用这些技术。 ### Apache DBCP **dataSource**: 配置数据源,通常在应用服务器的配置文件...

    数据库连接池以及hibernate对各种连接池的整合

    10. **BoneCP**:快速且开源的连接池,比C3P0和DBCP快25倍,适合性能敏感的应用。 在配置Hibernate与连接池的整合时,需要注意以下几点: 1. **Apache DBCP**:在Hibernate 2中支持,但在Hibernate 3中不推荐,...

    关于JAVA的数据库连接池的探讨.pdf

    对于提供连接池的数据源来说,除了Apache的DBCP以外,还有C3P0、Proxool、BoneCP等。具体如表1所示。 表1 基于JAVA的带连接池的数据源组件 序号 数据源名称 依赖的JAR包 实现的功能 1 Apache DBCP dbcp.jar、pool....

    Druid数据库连接池Jar包

    Druid是目前最好的数据库连接池,在功能、性能、扩展性方面,都超过其他数据库连接池,包括DBCP、C3P0、BoneCP、Proxool、JBoss DataSource。Druid已经在阿里巴巴部署了超过600个应用,经过一年多生产环境大规模部署...

    druid-1.0.19

    Druid是目前最好的数据库连接池,在功能、性能、扩展性方面,都超过其他数据库连接池,包括DBCP、C3P0、BoneCP、Proxool、JBoss DataSource。 Druid已经在阿里巴巴部署了超过600个应用,经过一年多生产环境大规模...

    druid-0.2.20

    Druid是目前最好的数据库连接池,在功能、性能、扩展性方面,都超过其他数据库连接池,包括DBCP、C3P0、BoneCP、Proxool、JBoss DataSource。 Druid已经在阿里巴巴部署了超过600个应用,经过一年多生产环境大规模...

    Java连接池评估报告

    3. **资源管理**:为了减少资源浪费并支持分布式系统,建议使用能够有效管理连接的连接池,如C3P0和BoneCP。 总之,选择合适的数据库连接池对于提升应用性能至关重要。开发者应根据具体的应用场景和技术要求来做出...

    Java-ConnectionPools.rar_连接池

    Java数据库连接池是一种重要的资源管理技术,用于优化数据库应用程序的性能和效率。它通过复用已建立的数据库连接,避免了频繁创建和销毁连接带来的开销。以下是对压缩包文件中涉及的几个主要连接池组件的详细介绍:...

    druid各版本jar包

    Druid首先是一个数据库连接池。Druid是目前最好的数据库连接池,在功能、性能、扩展性方面,都超过其他数据库连接池,包括DBCP、C3P0、BoneCP、Proxool、JBoss DataSource。

    druid-1.0.25

    Druid是阿里巴巴的开源产品,目前最好的数据库连接池,在功能、性能、扩展性方面,都超过其他数据库连接池,包括DBCP、C3P0、BoneCP、Proxool、JBoss DataSource。

    druid-1.1.12.jar

    Druid首先是一个数据库连接池。Druid是目前最好的数据库连接池,在功能、性能、扩展性方面,都超过其他数据库连接池,包括DBCP、C3P0、BoneCP、Proxool、JBoss DataSource。

    druid-1.0.11.jar

    Druid是目前最好的数据库连接池,在功能、性能、扩展性方面,都超过其他数据库连接池,包括DBCP、C3P0、BoneCP、Proxool、JBoss DataSource。 Druid已经在阿里巴巴部署了超过600个应用,经过一年多生产环境大规模...

    几种常用的Java数据源解决方案

    本文将详细介绍几种常用的数据源解决方案及其配置方法,包括JNDI方式创建`DataSource`、Apache提供的简单连接池创建数据源、C3P0方式创建数据源、Proxool方式创建数据源以及BoneCP方式创建数据源。 #### JNDI 方式...

    软件性能优化最佳实践

    不同的连接池(如c3p0、dbcp、Proxool等)在性能和稳定性方面有所不同。例如,BoneCP在性能方面表现出色,而DBCP则更稳定。 - **批量数据处理:** 针对大批量数据处理任务,建议直接使用JDBC,以获得更好的性能。 *...

    基于SSM架构实现的大型分布式购物网站-B2C项目源码+项目说明.zip

    Druid是目前最好的数据库连接池,在功能、性能、扩展性方面,都超过其他数据库连接池,包括DBCP、C3P0、BoneCP、Proxool、JBoss DataSource。 Druid已经在阿里巴巴部署了超过600个应用,经过多年多生产环境大规模...

Global site tag (gtag.js) - Google Analytics