<maximum-active-time>15000</maximum-active-time> 单位毫秒,当一个数据库的操作时间大于这个值,将给kill这个链接,控制台会出现如下信息:
WARN [ABC] proxool.default (ABC.java:149) - #0001 was active for 324234 milliseconds and has been removed automaticaly. The Thread responsible was named ‘Thread-1′, but the last SQL it performed is unknown because the trace property is not enabled.
【参见:http://it.oyksoft.com/post/3983/】 。
=================================
获取 DBConnection 如下:
==========================
package com.xc.tools;
import java.net.URL;
import java.sql.*;
import org.logicalcobwebs.proxool.ProxoolException;
import org.logicalcobwebs.proxool.ProxoolFacade;
import org.logicalcobwebs.proxool.configuration.JAXPConfigurator;
import org.logicalcobwebs.proxool.admin.SnapshotIF;
public class DBConnection
{
private static boolean initialized = false;
private static int activeCount = 0;
public Connection getConnection() throws SQLException
{
Connection connection = null;
if (!initialized)
{
init();
}
connection = DriverManager.getConnection("proxool.phrConn");
try
{
SnapshotIF snapshot = ProxoolFacade.getSnapshot("phrConn", true);
int curActiveCount = snapshot.getActiveConnectionCount();// 获得活动连接数
int availableCount = snapshot.getAvailableConnectionCount();// 获得可得到的连接数
int maxCount = snapshot.getMaximumConnectionCount();// 获得总连接数
if (curActiveCount != activeCount)// 当活动连接数变化时输出信息
{
System.out.println("----------------------------------");
System.out
.println(curActiveCount + "(active) " + availableCount
+ "(available) " + maxCount + "(max)");
System.out.println("----------------------------------");
activeCount = curActiveCount;
}
} catch (ProxoolException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
if (connection != null)
{
return connection;
} else
{
throw new NullPointerException(
"Didn‘t get connection, which probably means that no Driver accepted the URL");
}
}
private static void init()
{
try {
Class.forName("org.logicalcobwebs.proxool.ProxoolDriver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
initialized = true;
}
}