在MySQL中,按照JSP代码不会发生连接泄漏。
伺服器:JBoss 7
MySQL版本:5.7
MySQL-connector-java-5.1.18.jar
为确保从Java代码泄漏连接,我在server.log中收到以下错误:
[org.jboss.jca.core.api.connectionmanager.ccm.CachedConnectionManager](http- / 0.0.0.0:80-7)IJ000100:为您关闭连接。请自行关闭它们:org.jboss.jca.adapters.jdbc.jdk6.WrappedConnectionJDK6@73a1aa:java.lang.Throwable:STACKTRACE
JSP code:
Statement st = null;
ResultSet rs = null;
Connection conn = null;
DataSource dataSource = null;
try{
dataSource = (DataSource) new InitialContext().lookup("java:/MySql");
conn = dataSource.getConnection();
st = conn.createStatement();
rs=st.executeQuery("select * from test.users");
} catch (Exception e) {
}
standalone.xml code
<datasource jta="true" jndi-name="java:/MySql" pool-name="MySql" enabled="true" use-java-context="true" use-ccm="true">
<connection-url>jdbc:mysql://localhost:3306/test?zeroDateTimeBehavior=convertToNull&useOldAliasMetadataBehavior=true&autoReconnect=true</connection-url>
<driver>com.mysql</driver>
<transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
<pool>
<min-pool-size>5</min-pool-size>
<max-pool-size>100</max-pool-size>
<prefill>true</prefill>
<use-strict-min>false</use-strict-min>
<flush-strategy>FailingConnectionOnly</flush-strategy>
</pool>
<security>
<user-name>web</user-name>
<password>123</password>
</security>
<timeout>
<idle-timeout-minutes>5</idle-timeout-minutes>
</timeout>
<statement>
<prepared-statement-cache-size>32</prepared-statement-cache-size>
<share-prepared-statements>true</share-prepared-statements>
</statement>
</datasource>
我已经访问了上面的JSP页面50次,并且MySQL进程列表中应该存在50个睡眠连接。但这没有发生。结果如下:
我已在MySQL查询浏览器中执行以下查询,以识别连接泄漏:
从INFORMATION_SCHEMA.processlist中选择id,主机,命令,时间,信息,其中user ='web';
实际结果:仅显示7个睡眠连接
预期结果:应该是50个睡眠连接
如果我错了,请帮助我理解该行为并纠正。
预先感谢