我们正在使用tomcat 6.0.26和MySql 5.1,在server.xml中设置了与数据库的连接,如下所示,
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
<Resource name="jdbc/abs" type="javax.sql.DataSource" maxActive="150" maxIdle="5" username="XXXXXXXXXXX" testWhileIdle="true" removeAbandonedTimeout="60" maxWait="-1" removeAbandoned="true"
validationQuery="select 1" driverClassName="com.mysql.jdbc.Driver" password="XXXXXXXXXXX" minEvictableIdleTimeMillis="30000" timeBetweenEvictionRunsMillis="300000" url="jdbc:mysql://XXXXXXXXXXXX?autoReconnect=true&useUnicode=true&characterEncoding=utf-8"/>
<Resource driverClassName="com.mysql.jdbc.Driver" maxActive="150" maxIdle="5" maxWait="-1" testWhileIdle="true" minEvictableIdleTimeMillis="30000" removeAbandonedTimeout="60" timeBetweenEvictionRunsMillis="300000" name="jdbc/1234" password="XXXXXXXXXXX" removeAbandoned="true" type="javax.sql.DataSource" url="jdbc:mysql:///XXXXXXXXXXXXXXXXXXXXXX?autoReconnect=true&useUnicode=true&characterEncoding=utf-8" username="XXXXXXXXXXX" validationQuery="select 1"/>
当我在MySql中运行show full processlist时,它显示了很多连接处于睡眠模式,这可能是什么造成的呢?
此致
罗希特夏尔
答案 0 :(得分:-1)
javax.sql.DataSource
是MySQL的连接池。您的应用程序服务器将打开一些与MySQL的连接(保持睡眠模式)并在每次执行时使用它们:
DataSource ds = ...;
// you get one of the 'sleeping' connections here
Connection conn = ds.getConnection();
// you return the connection to the pool here (it does not actually closes it)
conn.close();