1 建立JNDI;打开$TOMCAT_HOME/conf/context.xml,添加如下
<!--MySQL-->
<Resource
name="jdbc/market"
auth="Container"
type="javax.sql.DataSource"
maxActive="100"
maxIdle="30"
maxWait="10000"
username="develop"
password="xxxxxx"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://mysql:3306/market"
/>
<!--SQL Server-->
<Resource
name="jdbc/market"
auth="Container"
type="javax.sql.DataSource"
maxActive="100"
maxIdle="30"
maxWait="10000"
username="sa"
password="xxxxxx"
driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
url="jdbc:sqlserver://sqlserver:1433;DatabaseName=market"
/>
2 优化连接数及压缩选项;打开$TOMCAT_HOME/conf/server.xml,替换如下代码:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8"
maxThreads="250" maxHttpHeaderSize="8192"
disableUploadTimeout="true"
acceptCount="440" emptySessionPath="true"
enableLookups="false"
compression="500" compressableMimeType="text/html,text/xml,text/plain,application/octet-stream"/>
3 优化JVM;打开$TOMCAT_HOME/bin/catalina.cmd(catalina.sh),在最上面添加如下
JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8
-server -Xms2048m -Xmx2048m
-XX:NewSize=512m -XX:MaxNewSize=512m -XX:PermSize=512m
-XX:MaxPermSize=512m -XX:+DisableExplicitGC"
4 修改Spring的连接,打开applicationContext.xml,修改如下:
<jee:jndi-lookup jndi-name="jdbc/market" id="dataSource"></jee:jndi-lookup>