2012-07-07 83 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(); 
相關問題