﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-fantasyginge-文章分类-Database</title><link>http://www.blogjava.net/fantasyginge/category/6254.html</link><description /><language>zh-cn</language><lastBuildDate>Sat, 26 May 2007 01:21:09 GMT</lastBuildDate><pubDate>Sat, 26 May 2007 01:21:09 GMT</pubDate><ttl>60</ttl><item><title>几种开源数据库连接池的使用感受</title><link>http://www.blogjava.net/fantasyginge/articles/36878.html</link><dc:creator>fantasyginge</dc:creator><author>fantasyginge</author><pubDate>Wed, 22 Mar 2006 08:15:00 GMT</pubDate><guid>http://www.blogjava.net/fantasyginge/articles/36878.html</guid><wfw:comment>http://www.blogjava.net/fantasyginge/comments/36878.html</wfw:comment><comments>http://www.blogjava.net/fantasyginge/articles/36878.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/fantasyginge/comments/commentRss/36878.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/fantasyginge/services/trackbacks/36878.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp;如需转载，请注明出自：&nbsp;&nbsp;<a href="http://www.blogjava.net/fantasyginge/">http://www.blogjava.net/fantasyginge/</a><br>&nbsp;&nbsp;&nbsp; 在项目中尝试使用了几种开源的数据库连接池实现。一种是dbcp，一种是c3p0，还有一种是proxool，这几种数据库连接池都可以很容易的在Spring配置起来。性能总体上上感觉dbcp为最优，因为稳定性和并发性都是我的项目需要的。<br>&nbsp;&nbsp;&nbsp;&nbsp; 项目中经过反复测试，如果web server和数据库server不是同一个机器的话，在断网时间比较短的时间内三种数据库连接池都能较好的重连，但是在断网时间超过8个钟头proxool就不能恢复工作了。但是dbcp却能很快的重新连接。实际生产环境中稳定性和总体性能是最重要的，都需要做相应的测试才能放心的让系统上生产线。<br><br><br>这里给出项目中数据库连接池配置：<br><br>dbcp的jndi：<br>
<div style="BORDER-RIGHT: rgb(204,204,204) 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: rgb(204,204,204) 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: rgb(204,204,204) 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: rgb(204,204,204) 1px solid; BACKGROUND-COLOR: rgb(238,238,238)"><span style="COLOR: rgb(0,128,128)">1</span><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">bean&nbsp;</span><span style="COLOR: rgb(255,0,0)">id</span><span style="COLOR: rgb(0,0,255)">="dataSource"</span><span style="COLOR: rgb(255,0,0)"><br></span><span style="COLOR: rgb(0,128,128)">2</span><span style="COLOR: rgb(255,0,0)"><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;class</span><span style="COLOR: rgb(0,0,255)">="org.springframework.jndi.JndiObjectFactoryBean"</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br></span><span style="COLOR: rgb(0,128,128)">3</span><span style="COLOR: rgb(0,0,0)"><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">property&nbsp;</span><span style="COLOR: rgb(255,0,0)">name</span><span style="COLOR: rgb(0,0,255)">="jndiName"</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br></span><span style="COLOR: rgb(0,128,128)">4</span><span style="COLOR: rgb(0,0,0)"><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">value</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)">java:comp/env/jdbc/mysql</span><span style="COLOR: rgb(0,0,255)">&lt;/</span><span style="COLOR: rgb(128,0,0)">value</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br></span><span style="COLOR: rgb(0,128,128)">5</span><span style="COLOR: rgb(0,0,0)"><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: rgb(0,0,255)">&lt;/</span><span style="COLOR: rgb(128,0,0)">property</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br></span><span style="COLOR: rgb(0,128,128)">6</span><span style="COLOR: rgb(0,0,0)"><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: rgb(0,0,255)">&lt;/</span><span style="COLOR: rgb(128,0,0)">bean</span><span style="COLOR: rgb(0,0,255)">&gt;</span></div>
<br>proxool(proxool-0.9.0RC1)的配置：<br>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">bean&nbsp;</span><span style="COLOR: #ff0000">id</span><span style="COLOR: #0000ff">="MySqlDataSource"</span><span style="COLOR: #ff0000"><br>&nbsp;&nbsp;class</span><span style="COLOR: #0000ff">="org.logicalcobwebs.proxool.ProxoolDataSource"</span><span style="COLOR: #ff0000"><br>&nbsp;&nbsp;lazy-init</span><span style="COLOR: #0000ff">="false"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;</span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">property&nbsp;</span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="driver"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">com.mysql.jdbc.Driver</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">property</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;</span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">property&nbsp;</span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="driverUrl"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">jdbc:mysql://ip:3306/dbname?useUnicode=true</span><span style="COLOR: #ff0000">&amp;amp;</span><span style="COLOR: #000000">characterEncoding=utf8</span><span style="COLOR: #ff0000">&amp;amp;</span><span style="COLOR: #000000">autoReconnect=true</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">property</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;</span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">property&nbsp;</span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="user"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">user</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">property</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;</span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">property&nbsp;</span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="password"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">password</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">property</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;</span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">property&nbsp;</span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="maximumConnectionCount"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">500</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">property</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;</span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">property&nbsp;</span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="houseKeepingSleepTime"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">15000</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">property</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;</span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">property&nbsp;</span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="houseKeepingTestSql"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">select&nbsp;CURRENT_DATE</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">property</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;</span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">property&nbsp;</span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="testBeforeUse"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">true</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">property</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;</span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">property&nbsp;</span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="alias"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">mysqlProxoolDataSource</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">property</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;</span><span style="COLOR: #008000">&lt;!--</span><span style="COLOR: #008000"><br>&nbsp;&nbsp;&lt;property&nbsp;name="maximumActiveTime"&gt;<br>&nbsp;&nbsp;&nbsp;&lt;value&gt;10000&lt;/value&gt;<br>&nbsp;&nbsp;&lt;/property&gt;<br>&nbsp;&nbsp;</span><span style="COLOR: #008000">--&gt;</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;</span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">property&nbsp;</span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="simultaneousBuildThrottle"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">1000</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">property</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;</span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">property&nbsp;</span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="trace"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">false</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">property</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br>&nbsp;</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">bean</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br><br><br><br><br>建议使用DBCP，配置在tomcat中，然后在spring中使用jndi的形式获取。</span></div>
<br>c3p0(c3p0-0.9.0)：<br>
<div style="BORDER-RIGHT: rgb(204,204,204) 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: rgb(204,204,204) 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: rgb(204,204,204) 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: rgb(204,204,204) 1px solid; BACKGROUND-COLOR: rgb(238,238,238)"><span style="COLOR: rgb(0,128,128)">&nbsp;1</span><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">bean&nbsp;</span><span style="COLOR: rgb(255,0,0)">id</span><span style="COLOR: rgb(0,0,255)">="dataSource"</span><span style="COLOR: rgb(255,0,0)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;class</span><span style="COLOR: rgb(0,0,255)">="com.mchange.v2.c3p0.ComboPooledDataSource"</span><span style="COLOR: rgb(255,0,0)"><br></span><span style="COLOR: rgb(0,128,128)">&nbsp;2</span><span style="COLOR: rgb(255,0,0)"><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;destroy-method</span><span style="COLOR: rgb(0,0,255)">="close"</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br></span><span style="COLOR: rgb(0,128,128)">&nbsp;3</span><span style="COLOR: rgb(0,0,0)"><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">property&nbsp;</span><span style="COLOR: rgb(255,0,0)">name</span><span style="COLOR: rgb(0,0,255)">="driverClass"</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br></span><span style="COLOR: rgb(0,128,128)">&nbsp;4</span><span style="COLOR: rgb(0,0,0)"><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">value</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)">com.mysql.jdbc.Driver</span><span style="COLOR: rgb(0,0,255)">&lt;/</span><span style="COLOR: rgb(128,0,0)">value</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br></span><span style="COLOR: rgb(0,128,128)">&nbsp;5</span><span style="COLOR: rgb(0,0,0)"><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: rgb(0,0,255)">&lt;/</span><span style="COLOR: rgb(128,0,0)">property</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br></span><span style="COLOR: rgb(0,128,128)">&nbsp;6</span><span style="COLOR: rgb(0,0,0)"><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">property&nbsp;</span><span style="COLOR: rgb(255,0,0)">name</span><span style="COLOR: rgb(0,0,255)">="jdbcUrl"</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br></span><span style="COLOR: rgb(0,128,128)">&nbsp;7</span><span style="COLOR: rgb(0,0,0)"><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">value</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)">jdbc:mysql://192.168.0.225:3306/sendinmdb?useUnicode=true</span><span style="COLOR: rgb(255,0,0)">&amp;amp;</span><span style="COLOR: rgb(0,0,0)">characterEncoding=utf8</span><span style="COLOR: rgb(255,0,0)">&amp;amp;</span><span style="COLOR: rgb(0,0,0)">autoReconnect=true</span><span style="COLOR: rgb(0,0,255)">&lt;/</span><span style="COLOR: rgb(128,0,0)">value</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br></span><span style="COLOR: rgb(0,128,128)">&nbsp;8</span><span style="COLOR: rgb(0,0,0)"><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: rgb(0,0,255)">&lt;/</span><span style="COLOR: rgb(128,0,0)">property</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br></span><span style="COLOR: rgb(0,128,128)">&nbsp;9</span><span style="COLOR: rgb(0,0,0)"><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">property&nbsp;</span><span style="COLOR: rgb(255,0,0)">name</span><span style="COLOR: rgb(0,0,255)">="user"</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br></span><span style="COLOR: rgb(0,128,128)">10</span><span style="COLOR: rgb(0,0,0)"><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">value</span><span style="COLOR: rgb(0,0,255)">&gt;********</span><span style="COLOR: rgb(0,0,255)">&lt;/</span><span style="COLOR: rgb(128,0,0)">value</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br></span><span style="COLOR: rgb(0,128,128)">11</span><span style="COLOR: rgb(0,0,0)"><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: rgb(0,0,255)">&lt;/</span><span style="COLOR: rgb(128,0,0)">property</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br></span><span style="COLOR: rgb(0,128,128)">12</span><span style="COLOR: rgb(0,0,0)"><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">property&nbsp;</span><span style="COLOR: rgb(255,0,0)">name</span><span style="COLOR: rgb(0,0,255)">="password"</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br></span><span style="COLOR: rgb(0,128,128)">13</span><span style="COLOR: rgb(0,0,0)"><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">value</span><span style="COLOR: rgb(0,0,255)">&gt;********</span><span style="COLOR: rgb(0,0,255)">&lt;/</span><span style="COLOR: rgb(128,0,0)">value</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br></span><span style="COLOR: rgb(0,128,128)">14</span><span style="COLOR: rgb(0,0,0)"><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: rgb(0,0,255)">&lt;/</span><span style="COLOR: rgb(128,0,0)">property</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br></span><span style="COLOR: rgb(0,128,128)">15</span><span style="COLOR: rgb(0,0,0)"><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">property&nbsp;</span><span style="COLOR: rgb(255,0,0)">name</span><span style="COLOR: rgb(0,0,255)">="maxPoolSize"</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br></span><span style="COLOR: rgb(0,128,128)">16</span><span style="COLOR: rgb(0,0,0)"><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">value</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)">100</span><span style="COLOR: rgb(0,0,255)">&lt;/</span><span style="COLOR: rgb(128,0,0)">value</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br></span><span style="COLOR: rgb(0,128,128)">17</span><span style="COLOR: rgb(0,0,0)"><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: rgb(0,0,255)">&lt;/</span><span style="COLOR: rgb(128,0,0)">property</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br></span><span style="COLOR: rgb(0,128,128)">18</span><span style="COLOR: rgb(0,0,0)"><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">property&nbsp;</span><span style="COLOR: rgb(255,0,0)">name</span><span style="COLOR: rgb(0,0,255)">="maxIdleTime"</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br></span><span style="COLOR: rgb(0,128,128)">19</span><span style="COLOR: rgb(0,0,0)"><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">value</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)">50</span><span style="COLOR: rgb(0,0,255)">&lt;/</span><span style="COLOR: rgb(128,0,0)">value</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br></span><span style="COLOR: rgb(0,128,128)">20</span><span style="COLOR: rgb(0,0,0)"><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: rgb(0,0,255)">&lt;/</span><span style="COLOR: rgb(128,0,0)">property</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br></span><span style="COLOR: rgb(0,128,128)">21</span><span style="COLOR: rgb(0,0,0)"><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">property&nbsp;</span><span style="COLOR: rgb(255,0,0)">name</span><span style="COLOR: rgb(0,0,255)">="maxStatementsPerConnection"</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br></span><span style="COLOR: rgb(0,128,128)">22</span><span style="COLOR: rgb(0,0,0)"><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">value</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)">100</span><span style="COLOR: rgb(0,0,255)">&lt;/</span><span style="COLOR: rgb(128,0,0)">value</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br></span><span style="COLOR: rgb(0,128,128)">23</span><span style="COLOR: rgb(0,0,0)"><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: rgb(0,0,255)">&lt;/</span><span style="COLOR: rgb(128,0,0)">property</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br></span><span style="COLOR: rgb(0,128,128)">24</span><span style="COLOR: rgb(0,0,0)"><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">property&nbsp;</span><span style="COLOR: rgb(255,0,0)">name</span><span style="COLOR: rgb(0,0,255)">="numHelperThreads"</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br></span><span style="COLOR: rgb(0,128,128)">25</span><span style="COLOR: rgb(0,0,0)"><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">value</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)">1000</span><span style="COLOR: rgb(0,0,255)">&lt;/</span><span style="COLOR: rgb(128,0,0)">value</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br></span><span style="COLOR: rgb(0,128,128)">26</span><span style="COLOR: rgb(0,0,0)"><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: rgb(0,0,255)">&lt;/</span><span style="COLOR: rgb(128,0,0)">property</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br></span><span style="COLOR: rgb(0,128,128)">27</span><span style="COLOR: rgb(0,0,0)"><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">property&nbsp;</span><span style="COLOR: rgb(255,0,0)">name</span><span style="COLOR: rgb(0,0,255)">="idleConnectionTestPeriod"</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br></span><span style="COLOR: rgb(0,128,128)">28</span><span style="COLOR: rgb(0,0,0)"><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">value</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)">30</span><span style="COLOR: rgb(0,0,255)">&lt;/</span><span style="COLOR: rgb(128,0,0)">value</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br></span><span style="COLOR: rgb(0,128,128)">29</span><span style="COLOR: rgb(0,0,0)"><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: rgb(0,0,255)">&lt;/</span><span style="COLOR: rgb(128,0,0)">property</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br></span><span style="COLOR: rgb(0,128,128)">30</span><span style="COLOR: rgb(0,0,0)"><img src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: rgb(0,0,255)">&lt;/</span><span style="COLOR: rgb(128,0,0)">bean</span><span style="COLOR: rgb(0,0,255)">&gt;</span></div>
<p><br><br><br>直接copy &amp; paste到spring配置文件里就可以使用了。</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>配置一些额外的tomcat 的DBCP连接池参数，也可以更好的使用到类似proxool提供的功能，只是dbcp更加稳定而已。</p>
<p>tomcat/conf/context.xml中插入一个Resource元素：<br></p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">Resource&nbsp;</span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="jdbc/mysql"</span><span style="COLOR: #ff0000">&nbsp;auth</span><span style="COLOR: #0000ff">="Container"</span><span style="COLOR: #ff0000">&nbsp;type</span><span style="COLOR: #0000ff">="javax.sql.DataSource"</span><span style="COLOR: #ff0000"><br>&nbsp;maxActive</span><span style="COLOR: #0000ff">="1000"</span><span style="COLOR: #ff0000">&nbsp;maxIdle</span><span style="COLOR: #0000ff">="30"</span><span style="COLOR: #ff0000">&nbsp;maxWait</span><span style="COLOR: #0000ff">="10000"</span><span style="COLOR: #ff0000"><br>&nbsp;username</span><span style="COLOR: #0000ff">="user"</span><span style="COLOR: #ff0000">&nbsp;password</span><span style="COLOR: #0000ff">="password"</span><span style="COLOR: #ff0000">&nbsp;driverClassName</span><span style="COLOR: #0000ff">="com.mysql.jdbc.Driver"</span><span style="COLOR: #ff0000"><br>&nbsp;validationQuery&nbsp;</span><span style="COLOR: #0000ff">=&nbsp;"select&nbsp;current_date()"</span><span style="COLOR: #ff0000"><br>&nbsp;testOnBorrow&nbsp;</span><span style="COLOR: #0000ff">=&nbsp;"true"</span><span style="COLOR: #ff0000">&nbsp;testOnReturn&nbsp;</span><span style="COLOR: #0000ff">=&nbsp;"false"</span><span style="COLOR: #ff0000">&nbsp;&nbsp;testWhileIdle&nbsp;</span><span style="COLOR: #0000ff">=&nbsp;"true"</span><span style="COLOR: #ff0000"><br>&nbsp;timeBetweenEvictionRunsMillis&nbsp;</span><span style="COLOR: #0000ff">=&nbsp;"15000"</span><span style="COLOR: #ff0000">&nbsp;numTestsPerEvictionRun&nbsp;</span><span style="COLOR: #0000ff">=&nbsp;"10"</span><span style="COLOR: #ff0000">&nbsp;minEvictableIdleTimeMillis&nbsp;</span><span style="COLOR: #0000ff">=&nbsp;"600000"</span><span style="COLOR: #ff0000"><br>&nbsp;url</span><span style="COLOR: #0000ff">="jdbc:mysql://ip:3306/sendinmdb?useUnicode=true&amp;amp;characterEncoding=utf8&amp;amp;autoReconnect=true"</span><span style="COLOR: #0000ff">/&gt;</span></div>
<p>&nbsp;</p>
<p>解释一下以下这些参数的含义：<br>validationQuery = "select current_date()"<br>&nbsp;testOnBorrow = "true"<br>&nbsp;testOnReturn = "false"&nbsp;<br>testWhileIdle = "true"<br><br>当从池中获取一个Connection后使用 select current_date() 来测试该数据库连接的可用性，如果SQL语句返回结果则认为是一个有效的连接，否则将继续测试知道可以拿到有效的连接。当返回Connection给池的时候不进行验证，但是Connection空闲的时候就要进行认证。<br><br><br>timeBetweenEvictionRunsMillis = "15000" <br>DBCP 清空线程睡眠的间隙，如值为负数则不运行该线程<br><br>numTestsPerEvictionRun = "10" <br>清空线程每次验证的连接对象个数<br><br><br>minEvictableIdleTimeMillis = "600000"</p>
Connection对象可以在池中空闲的最小时间，单位为毫秒<br><br><br>详细配置请访问<br><a href="http://jakarta.apache.org/commons/dbcp/configuration.html">http://jakarta.apache.org/commons/dbcp/configuration.html</a>
<img src ="http://www.blogjava.net/fantasyginge/aggbug/36878.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/fantasyginge/" target="_blank">fantasyginge</a> 2006-03-22 16:15 <a href="http://www.blogjava.net/fantasyginge/articles/36878.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>