java proxool系统设置
1.在maven配置文件pom.xml中增加dependencies
<dependency>
<groupId>com.cloudhopper.proxool</groupId>
<artifactId>proxool</artifactId>
<version>0.9.1</version>
</dependency>
2.等待自动安装完毕后,修改WEB-INF目录下的proxool.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<something-else-entirely>
<proxool>
<alias>DBPool</alias>
<driver-url>jdbc:mysql://localhost:3306/test</driver-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<driver-properties>
<property name="user" value="root" />
<property name="password" value="geoidc.com" />
</driver-properties>
<house-keeping-sleep-time>60000</house-keeping-sleep-time>
<maximum-connection-count>10</maximum-connection-count>
<minimum-connection-count>2</minimum-connection-count>
<prototype-count>0</prototype-count>
<simultaneous-build-throttle>20</simultaneous-build-throttle>
<house-keeping-test-sql>select CURRENT_DATE</house-keeping-test-sql>
<statistics>15s,10m,1d</statistics>
<statistics-log-level>INFO</statistics-log-level>
</proxool>
</something-else-entirely>
3.创建一个单例DBManager来管理连接池
package com.newlysoft.controller;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import org.logicalcobwebs.proxool.configuration.JAXPConfigurator;
public class DBManager {
private String poolPath;
private DBManager() {
try {
this.poolPath = "D:\\javaprogram\\oasys\\target\\wxoa\\WEB-INF\\proxool.xml";
JAXPConfigurator.configure(this.poolPath, false);
Class.forName("org.logicalcobwebs.proxool.ProxoolDriver");
} catch (Exception var2) {
System.out.println("error ");
}
}
public Connection getConnection(String poolname) throws SQLException {
return DriverManager.getConnection(poolname);
}
public static DBManager getDBManager() {
return DBManager.DBManagerDAO.dbManager;
}
private static class DBManagerDAO {
private static final DBManager dbManager = new DBManager();
private DBManagerDAO() {
}
}
}
4.在程序中获取conn
DBManager man=DBManager.getDBManager();
Connection conn=man.getConnection("proxool.DBPool");