Tomcat 連接池配製

 

將下列代碼放到tomcat的server.xml文件中的<host></host>之間

<Context path=”/huaxuntong” reloadable=”true” docBase=”d:/programe/java/huaxuntong/web” debug=”0″>
<Logger className=”org.apache.catalina.logger.FileLogger”
prefix=”localhost_test_log.” suffix=”.txt” timestamp=”true”/>
<Resource name=”jdbc/huaxuntongdb” auth=”Container” type=”javax.sql.DataSource”
factory=”org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory”
username=”root”
password=”"
driverClassName=”com.mysql.jdbc.Driver”
url=”jdbc:mysql://localhost:3306/huaxuntongdb?autoReconnect=true&useUnicode=true&characterEncoding=utf-8&mysqlEncoding=utf8″
maxWait=”1000″ removeAbandoned=”true”
maxActive=”100″ maxIdle=”30″
removeAbandonedTimeout=”60″ logAbandoned=”true”/>
</Context>

href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml" rel="File-List">maxActive最大激活連接數,表示同時最多有100個與數據庫的連接。
maxWait最大等待秒鐘數,這裏取值-1,表示無限等待,直到超時爲止,也可以取值9000,即表示9秒後超時。
maxIdle是最大的空閒連接數,是一些與數據庫的連接始終是保持着的,當你的應用程序要訪問數據庫的時候就可以優先使用這些連接,以提高速度,如果這 些連接數不夠的話纔會重新建立一些連接, 這裏取值30個,表示即使沒有連接請求時,依然可以保持30空閒的連接,而不被清除,隨時處於待命狀態。

在已發佈項目的WEB-INF目錄下放置一個web.xml 內容如下:
<!DOCTYPE web-app
PUBLIC “-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN”
“http://java.sun.com/dtd/web-app_2_3.dtd”>

<web-app>

<display-name>demo</display-name>
<description>    demo </description>

<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/demo</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>

發佈了43 篇原創文章 · 獲贊 4 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章