1

我们在 MySql 5.1 中使用 tomcat 6.0.26,与数据库的连接在 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&amp;useUnicode=true&amp;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&amp;useUnicode=true&amp;characterEncoding=utf-8" username="XXXXXXXXXXX" validationQuery="select 1"/>

当我在 MySql 中运行 show full processlist 时,它显示大量连接处于睡眠模式,这可能是什么原因造成的?

问候,

罗希特

4

1 回答 1

-1

Ajavax.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();
于 2012-07-07T16:06:51.373 回答