2012-07-07 67 views
1

我们使用Tomcat 6.0.26与MySQL 5.1,如下面给出的,以数据库的连接是建立在server.xml中,Tomcat的不关闭连接,仍然在睡眠模式下

<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,它显示很多连接仍处于睡眠模式,可能会导致这种情况?

问候,

罗希特

+0

我面临同样的问题。你能解决这个问题吗? – 2017-07-23 14:49:30

回答

-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(); 
相关问题