Tomcat配置多線程和配置數據庫連接池
1、 tomcat配置線程池:
[root@RD2_AS yanghuihui]# cd /usr/tomcat/conf/
[root@RD2_AS conf]# vi server.xml
第一步,打開共享的線程池
源碼
<Service name="Catalina">
<!--The connectors can use a shared executor, you can define one or more named thread pools-->
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="1000" minSpareThreads="50" maxIdleTime="600000"/>
默認前后是注釋<!-- -->掉的,去掉就可以了。
第二步在 Connector里指定使用共享線程池
<Connector port="80" protocol="HTTP/1.1" redirectPort="8443" connectionTimeout="20000" executor="tomcatThreadPool" acceptCount="100" useBodyEncodingForURI="true" enableLookups="false" />
注意:在server.xml配置文件中,Connector有兩種,一種是不帶線程池的,一種是帶線程池的,並且port都是8080,這個時候就只能使一個有效,否則出現端口沖突,或者更改端口號不一致。並且wapi服務器要求端口號設置為80.
2、 Tomcat配置數據庫連接池
第一步需要拷貝mysql-connector-java-5.0.4-bin.jar到tomcat安裝目錄的lib目錄下
第二步配置tomcat配置文件目錄conf下的context.xml文件,在<context></context>之間添加連接池如下:
<Resource name="jdbc/mysql"
auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/wapi_as_db"
username="liuxc"
password="liuxianchun"
maxActive="100"
maxIdle="30"
maxWait="10000" />
第三步配置一下應用程序的web.xml文件:<web-app></web-app>之間加入:
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/mysql</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>