web.xml中
<servlet>
<servlet-name>ServletConfigurator</servlet-name>
<servlet-class>
org.logicalcobwebs.proxool.configuration.ServletConfigurator
</servlet-class>
<init-param>
<param-name>xmlFile</param-name>
<param-value>WEB-INF/proxool.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>dbpool</servlet-name>
<servlet-class>
org.logicalcobwebs.proxool.admin.servlet.AdminServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>dbpool</servlet-name>
<url-pattern>/dbpool</url-pattern>
</servlet-mapping>
proxool.xml
<?xml version="1.0" encoding="UTF-8"?>
<pools>
<proxool>
<alias>base</alias>
<driver-url>
jdbc:jtds:sqlserver://localhost:1433/aaa
</driver-url>
<driver-class>net.sourceforge.jtds.jdbc.Driver</driver-class>
<driver-properties>
<property name="user" value="sa" />
<property name="password" value="sa" />
</driver-properties>
<house-keeping-sleep-time>90000</house-keeping-sleep-time>
<simultaneous-build-throttle>130</simultaneous-build-throttle>
<prototype-count>3</prototype-count>
<maximum-connection-count>100</maximum-connection-count>
<minimum-connection-count>3</minimum-connection-count>
</proxool>
<proxool>
<alias>project</alias>
<driver-url>
jdbc:jtds:sqlserver://localhost:1433/bbb
</driver-url>
<driver-class>net.sourceforge.jtds.jdbc.Driver</driver-class>
<driver-properties>
<property name="user" value="sa" />
<property name="password" value="sa" />
</driver-properties>
<house-keeping-sleep-time>90000</house-keeping-sleep-time>
<simultaneous-build-throttle>130</simultaneous-build-throttle>
<prototype-count>3</prototype-count>
<maximum-connection-count>100</maximum-connection-count>
<minimum-connection-count>3</minimum-connection-count>
</proxool>
</pools>
public class PoolManager {
private static PoolManager instance=new PoolManager();
private static int activeCount = 0;
private final Logger logger = Logger.getLogger(getClass());
private PoolManager(){
try {
Class.forName("org.logicalcobwebs.proxool.ProxoolDriver");
logDebug("加载Proxool驱动成功");
} catch (ClassNotFoundException e) {
logDebug("加载Proxool驱动失败",e);
e.printStackTrace();
throw new RuntimeException("加载Proxool驱动失败",e);
}
}
public static PoolManager getInstance(){
return instance;
}
public Connection getConnection(String database) {
try{
//proxool驱动类
Connection conn = DriverManager.getConnection(database);
logDebug("getConnection for "+database);
System.out.println("getConnection");
//此处的DBPool是在proxool.xml中配置的连接池别名
// showSnapshotInfo(database);
return conn;
}catch(Exception ex){
logDebug("error when get connection for "+database, ex);
ex.printStackTrace();
return null;
}
}