- 浏览: 128018 次
- 性别:
- 来自: 杭州
文章分类
- 全部博客 (145)
- java (145)
- Java网络编程 (1)
- SWT 文本框Text通过GC重绘改变边框颜色 (1)
- tomcat部署web工程的两种方法 (1)
- JAX-RS 从傻逼到牛叉 1:REST 基础知识 (1)
- FreyjaJdbcTemplate 大致上完工了,想请人重构。。 (1)
- 开始认识自己 (1)
- 设计模式-Abstract Factory 模式 (1)
- 数据库中主键的设计原则 (1)
- JNI中jstring类型与c语言中的字符串的转换 (1)
- mac环境变量 (1)
- STC单片机ADC转换的例子 (1)
- myeclipse 8下安装Ibator . (1)
- OSGI与Android结合 (1)
- CSDN BLOG EXPERT (1)
- Java中网络操作的开源库CommonsNet (1)
- Apache License Version 2.0 英文内容及中文翻译 (1)
- JTest (1)
- GeoCon 用C#编写的开源的地理信息数据转换工具 (1)
- ERP简易教程 (1)
- 提高站点在搜索引擎上的排名 (1)
- Wifi (1)
- 腾讯Q+开放平台,相信又是一次成功的模仿 (1)
- C#坦克大战网络版代码 (1)
- Problem16 (1)
- Ajax 应该变成 Ajaj (关于JSON 与 XML 的比较) (1)
- ava框架数据库连接池比较(c3p0 (1)
- dbcp和proxool)bonecp (1)
- 继续向成熟男人靠拢 (1)
- Qt4.7中 默认的构造函数 (1)
- xml CDATA (1)
- 只针对中英文混合分词的中文分词器 (1)
- 典型相关分析及其适用范围和spss操作(转) (1)
- llvm (1)
- java连接数据库Oracle|DB2|Sql Server|Sybase|Informix|MySQL||PostgreSQL|access (1)
最新评论
-
xm3530:
什么鬼?都没法看,发出来干嘛
Android中利用App实现消息推送机制的代码实例 -
lvtenglongxiaohei:
太经典了!
学习一下!
ERP简易教程 -
lvtenglongxiaohei:
<br> 一天中午,丈 ...
ERP简易教程 -
hzw2312:
加油~~~!!!
开始认识自己 -
123048591:
显示乱码
tomcat部署web工程的两种方法
ava框架数据库连接池比较(c3p0,dbcp和proxool)bonecp
<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;password=root&amp;amp;useUnicode=true&amp;amp;characterEncoding=UTF-8&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>
发表评论
-
java连接数据库Oracle|DB2|Sql Server|Sybase|Informix|MySQL||PostgreSQL|access
2012-02-08 14:17 1064<div>Java数据库连接(JDBC)由 ... -
llvm
2012-02-07 16:29 883llvm ... -
典型相关分析及其适用范围和spss操作(转)
2012-02-07 15:43 1585看文章《科学学研 ... -
只针对中英文混合分词的中文分词器
2012-02-03 10:39 1016该版本说明 1、只针对中英文混合分词 需要一些中文和 ... -
xml CDATA
2012-02-03 08:45 1213<h2 style="font-si ... -
Qt4.7中 默认的构造函数
2012-02-01 09:14 1093<p><span style=&qu ... -
继续向成熟男人靠拢
2012-01-11 17:04 883转自徒儿的人人。 ... -
Ajax 应该变成 Ajaj (关于JSON 与 XML 的比较)
2011-12-28 15:23 967<span style="font- ... -
Problem16
2011-12-28 12:53 671package com.shui.mu.yao.io. ... -
C#坦克大战网络版代码
2011-12-20 13:09 992简单C#坦克大战网络版代码 写完单机版 http ... -
腾讯Q+开放平台,相信又是一次成功的模仿
2011-12-20 10:44 865今天看到两则新 ... -
Wifi
2011-12-19 13:14 1091. Confirm if Wifi is On ... -
提高站点在搜索引擎上的排名
2011-12-19 12:04 942对于拥有网站的各位站长来说,都希望自己的站点能够在各种 ... -
ERP简易教程
2011-12-16 16:47 925注明:下面的帖子 ... -
GeoCon 用C#编写的开源的地理信息数据转换工具
2011-12-14 12:29 958<p class="MsoNorma ... -
JTest
2011-12-14 09:00 1031接到parasoft公司一位先生打来的电话,说下个月第 ... -
Apache License Version 2.0 英文内容及中文翻译
2011-12-13 12:59 2349</span> <p class= ... -
Java中网络操作的开源库CommonsNet
2011-12-13 12:39 819<p class="MsoNorma ... -
CSDN BLOG EXPERT
2011-12-13 08:59 1100<img src="http://p. ... -
OSGI与Android结合
2011-12-12 12:09 879将当前最优秀的OSGI框架,与当前最火热的Androi ...
相关推荐
本文将详细介绍几个常见的Java数据库连接池实现:C3P0、Druid、JNDI、DBCP、Proxool以及BoneCP,并结合Spring+MyBatis+maven环境下的应用示例进行解析。 1. C3P0: C3P0是一个开源的JDBC连接池,它实现了数据源和...
在Spring3中配置数据源,包括DBCP,C3P0,Proxool,Bonecp主要的数据源,里面包含这些数据源的jar文件和依赖文件及配置文件。。 如Bonecp目前听说是最快的数据源,速度是传统的c3p0的25倍, bonecp.properties文件: ...
本文将详细介绍四个常见的Java数据连接池组件——C3PO、Proxool、DBCP和BoneCP的配置与用法。 首先,我们来看C3PO(Comprehensive3rdPartyPooling),这是一个基于Apache Commons DBCP的数据库连接池实现,具有更好...
本文将深入解析几种常用的数据库连接池——Apache DBCP、C3P0、Proxool、BoneCP的详细配置参数,帮助开发者更好地理解和应用这些技术。 ### Apache DBCP **dataSource**: 配置数据源,通常在应用服务器的配置文件...
10. **BoneCP**:快速且开源的连接池,比C3P0和DBCP快25倍,适合性能敏感的应用。 在配置Hibernate与连接池的整合时,需要注意以下几点: 1. **Apache DBCP**:在Hibernate 2中支持,但在Hibernate 3中不推荐,...
对于提供连接池的数据源来说,除了Apache的DBCP以外,还有C3P0、Proxool、BoneCP等。具体如表1所示。 表1 基于JAVA的带连接池的数据源组件 序号 数据源名称 依赖的JAR包 实现的功能 1 Apache DBCP dbcp.jar、pool....
Druid是目前最好的数据库连接池,在功能、性能、扩展性方面,都超过其他数据库连接池,包括DBCP、C3P0、BoneCP、Proxool、JBoss DataSource。Druid已经在阿里巴巴部署了超过600个应用,经过一年多生产环境大规模部署...
Druid是目前最好的数据库连接池,在功能、性能、扩展性方面,都超过其他数据库连接池,包括DBCP、C3P0、BoneCP、Proxool、JBoss DataSource。 Druid已经在阿里巴巴部署了超过600个应用,经过一年多生产环境大规模...
Druid是目前最好的数据库连接池,在功能、性能、扩展性方面,都超过其他数据库连接池,包括DBCP、C3P0、BoneCP、Proxool、JBoss DataSource。 Druid已经在阿里巴巴部署了超过600个应用,经过一年多生产环境大规模...
3. **资源管理**:为了减少资源浪费并支持分布式系统,建议使用能够有效管理连接的连接池,如C3P0和BoneCP。 总之,选择合适的数据库连接池对于提升应用性能至关重要。开发者应根据具体的应用场景和技术要求来做出...
Java数据库连接池是一种重要的资源管理技术,用于优化数据库应用程序的性能和效率。它通过复用已建立的数据库连接,避免了频繁创建和销毁连接带来的开销。以下是对压缩包文件中涉及的几个主要连接池组件的详细介绍:...
Druid首先是一个数据库连接池。Druid是目前最好的数据库连接池,在功能、性能、扩展性方面,都超过其他数据库连接池,包括DBCP、C3P0、BoneCP、Proxool、JBoss DataSource。
Druid是阿里巴巴的开源产品,目前最好的数据库连接池,在功能、性能、扩展性方面,都超过其他数据库连接池,包括DBCP、C3P0、BoneCP、Proxool、JBoss DataSource。
Druid首先是一个数据库连接池。Druid是目前最好的数据库连接池,在功能、性能、扩展性方面,都超过其他数据库连接池,包括DBCP、C3P0、BoneCP、Proxool、JBoss DataSource。
Druid是目前最好的数据库连接池,在功能、性能、扩展性方面,都超过其他数据库连接池,包括DBCP、C3P0、BoneCP、Proxool、JBoss DataSource。 Druid已经在阿里巴巴部署了超过600个应用,经过一年多生产环境大规模...
本文将详细介绍几种常用的数据源解决方案及其配置方法,包括JNDI方式创建`DataSource`、Apache提供的简单连接池创建数据源、C3P0方式创建数据源、Proxool方式创建数据源以及BoneCP方式创建数据源。 #### JNDI 方式...
不同的连接池(如c3p0、dbcp、Proxool等)在性能和稳定性方面有所不同。例如,BoneCP在性能方面表现出色,而DBCP则更稳定。 - **批量数据处理:** 针对大批量数据处理任务,建议直接使用JDBC,以获得更好的性能。 *...
Druid是目前最好的数据库连接池,在功能、性能、扩展性方面,都超过其他数据库连接池,包括DBCP、C3P0、BoneCP、Proxool、JBoss DataSource。 Druid已经在阿里巴巴部署了超过600个应用,经过多年多生产环境大规模...