- 浏览: 351698 次
- 性别:
- 来自: 杭州
文章分类
- 全部博客 (160)
- webservice (2)
- 数据库开发 (9)
- LINUX (6)
- 团队协作 (5)
- 前端技术 (4)
- J2EE (31)
- web服务器 (9)
- 经验常识 (12)
- 开发工具 (17)
- 项目管理 (7)
- 重构与设计模式 (8)
- 安全技术 (1)
- 并发编程 (1)
- 移动互联网 (2)
- 编码风格 (1)
- 领域建模 (1)
- 随想杂记 (12)
- 翻译 (2)
- 问题排查 (2)
- 数据挖掘 (4)
- 软件架构 (1)
- java语言基础知识 (13)
- 文件读写 (1)
- mac研发笔记 (1)
- 网络问题 (1)
- python学习 (0)
- Java8新特性 (1)
- soft kes collections (1)
最新评论
-
cremains:
...
java8新特性学习笔记 -
bingyingao:
guooo 写道很好的总结,不知能否转载?可以,多谢关注
又四年了,再看如何快速融入一个新团队 -
guooo:
很好的总结,不知能否转载?
又四年了,再看如何快速融入一个新团队 -
omeweb:
又过了好几年了,有啥新感悟没有?
两年已过去,再看该如何快速融入新团队 -
kely39:
感谢楼主,问题已解决
包冲突问题的解决方法
package org.logicalcobwebs.proxool;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Properties;
import java.util.StringTokenizer;
import javax.naming.Context;
import javax.naming.Name;
import javax.naming.RefAddr;
import javax.naming.Reference;
import javax.naming.StringRefAddr;
import javax.naming.spi.ObjectFactory;
import javax.sql.DataSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class ProxoolDataSource
implements DataSource, ObjectFactory
{
private static final Log LOG = LogFactory.getLog(ProxoolDataSource.class);
private int loginTimeout;
private PrintWriter logWriter;
private String alias;//是连接池的别名
private String driver;//数据库驱动
private String fatalSqlExceptionWrapperClass;
private long houseKeepingSleepTime;//保留线程处于睡眠状态的最长时间,house keeper 的职责就是检查各个连接的状态,并判断是否需要销毁或者创建.
//自动侦察各个连接状态的时间间隔(毫秒),侦察到空闲的连接就马上回收,超时的销毁 默认30秒,视乎不允许被赋值;
private String houseKeepingTestSql;// 如果发现了空闲的数据库连接.house keeper 将会用这个语句来测试.这个语句最好非常快的被执行.如果没有定义,测试过程将会被忽略。
private long maximumActiveTime;//如果housekeeper 检测到某个线程的活动时间大于这个数值.它将会杀掉这个线程.所以确认一下你的服务器的带宽.然后定一个合适的值.默认是5分钟
private int maximumConnectionCount;//最大连接数
private long maximumConnectionLifetime;//一个线程的最大寿命.
private int minimumConnectionCount;//最小链接数
private long overloadWithoutRefusalLifetime;//这可以帮助我们确定连接池的状态。如果我们已经拒绝了一个连接在这个设定值(毫秒),然后被认为是超载。默认为60秒。
private String password;//数据库密码
private int prototypeCount;//最少保持的空闲连接数 (默认5个)-->
private long recentlyStartedThreshold;//这可以帮助我们确定连接池的状态,连接数少还是多或超载。只要至少有一个连接已开始在此值(毫秒)内,或者有一些多余的可用连接,那么我们假设连接池是开启的。默认为60秒
private int simultaneousBuildThrottle;//这是我们可一次建立的最大连接数。那就是新增的连接请求,但还没有可供使用的连接。由于连接可以使用多线程,在有限的时间之间建立联系从而带来可用连接,但是我们需要通过一些方式确认一些线程并不是立即响应连接请求的,默认是10。
private String statistics;//连接池使用状况统计。 参数“10s,1m,1d”
private String statisticsLogLevel;//日志统计跟踪类型。 参数“ERROR”或 “INFO”
private boolean trace;// 如果为true,那么每个被执行的SQL语句将会在执行期被log记录(DEBUG LEVEL).你也可以注册一个ConnectionListener (参看ProxoolFacade)得到这些信息.
private String driverUrl;//数据库链接字符串
private String user;//数据库用户名
private boolean verbose;
private boolean jmx;
private String jmxAgentId;
private boolean testBeforeUse;//如果为true,在每个连接被测试前都会服务这个连接,如果一个连接失败,那么将被丢弃,另一个连接将会被处理,如果所有连接都失败,一个新的连接将会被建立。否则将会抛出一个SQLException异常。
private boolean testAfterUse;//如果为true,在每个连接被测试后都会服务这个连接,使其回到连接池中,如果连接失败,那么将被废弃
private Properties delegateProperties = new Properties();
private String fatalSqlExceptionsAsString;
public ProxoolDataSource()
{
reset();
}
public ProxoolDataSource(String alias) {
this.alias = alias;
}
public Connection getConnection()
throws SQLException
{
ConnectionPool cp = null;
try {
if (!ConnectionPoolManager.getInstance().isPoolExists(this.alias)) {
registerPool();
}
cp = ConnectionPoolManager.getInstance().getConnectionPool(this.alias);
return cp.getConnection();
} catch (ProxoolException e) {
LOG.error("Problem getting connection", e);
}throw new SQLException(e.toString());
}
private synchronized void registerPool()
throws ProxoolException
{
if (!ConnectionPoolManager.getInstance().isPoolExists(this.alias)) {
ConnectionPoolDefinition cpd = new ConnectionPoolDefinition();
cpd.setAlias(getAlias());
cpd.setDriver(getDriver());
cpd.setFatalSqlExceptionsAsString(getFatalSqlExceptionsAsString());
cpd.setFatalSqlExceptionWrapper(getFatalSqlExceptionWrapperClass());
cpd.setHouseKeepingSleepTime(getHouseKeepingSleepTime());
cpd.setHouseKeepingTestSql(getHouseKeepingTestSql());
cpd.setMaximumActiveTime(getMaximumActiveTime());
cpd.setMaximumConnectionCount(getMaximumConnectionCount());
cpd.setMaximumConnectionLifetime(getMaximumConnectionLifetime());
cpd.setMinimumConnectionCount(getMinimumConnectionCount());
cpd.setOverloadWithoutRefusalLifetime(getOverloadWithoutRefusalLifetime());
cpd.setPrototypeCount(getPrototypeCount());
cpd.setRecentlyStartedThreshold(getRecentlyStartedThreshold());
cpd.setSimultaneousBuildThrottle(getSimultaneousBuildThrottle());
cpd.setStatistics(getStatistics());
cpd.setStatisticsLogLevel(getStatisticsLogLevel());
cpd.setTrace(isTrace());
cpd.setUrl(getDriverUrl());
cpd.setVerbose(isVerbose());
cpd.setJmx(isJmx());
cpd.setJmxAgentId(getJmxAgentId());
cpd.setTestAfterUse(isTestAfterUse());
cpd.setTestBeforeUse(isTestBeforeUse());
cpd.setDelegateProperties(this.delegateProperties);
cpd.setUser(getUser());
cpd.setPassword(getPassword());
ProxoolFacade.registerConnectionPool(cpd);
}
}
public Object getObjectInstance(Object refObject, Name name, Context context, Hashtable hashtable)
throws Exception
{
if (!(refObject instanceof Reference)) {
return null;
}
Reference reference = (Reference)refObject;
if (!ConnectionPoolManager.getInstance().isPoolExists(reference.get("proxool.alias").toString())) {
populatePropertiesFromReference(reference);
}
return this;
}
public String getAlias()
{
return this.alias;
}
public void setAlias(String alias)
{
this.alias = alias;
}
public String getDriverUrl()
{
return this.driverUrl;
}
public void setDriverUrl(String url)
{
this.driverUrl = url;
}
public String getDriver()
{
return this.driver;
}
public void setDriver(String driver)
{
this.driver = driver;
}
public long getMaximumConnectionLifetime()
{
return this.maximumConnectionLifetime;
}
public void setMaximumConnectionLifetime(int maximumConnectionLifetime)
{
this.maximumConnectionLifetime = maximumConnectionLifetime;
}
public int getPrototypeCount()
{
return this.prototypeCount;
}
public void setPrototypeCount(int prototypeCount)
{
this.prototypeCount = prototypeCount;
}
public int getMinimumConnectionCount()
{
return this.minimumConnectionCount;
}
public void setMinimumConnectionCount(int minimumConnectionCount)
{
this.minimumConnectionCount = minimumConnectionCount;
}
public int getMaximumConnectionCount()
{
return this.maximumConnectionCount;
}
public void setMaximumConnectionCount(int maximumConnectionCount)
{
this.maximumConnectionCount = maximumConnectionCount;
}
public long getHouseKeepingSleepTime()
{
return this.houseKeepingSleepTime;
}
public void setHouseKeepingSleepTime(int houseKeepingSleepTime)
{
this.houseKeepingSleepTime = houseKeepingSleepTime;
}
public int getSimultaneousBuildThrottle()
{
return this.simultaneousBuildThrottle;
}
public void setSimultaneousBuildThrottle(int simultaneousBuildThrottle)
{
this.simultaneousBuildThrottle = simultaneousBuildThrottle;
}
public long getRecentlyStartedThreshold()
{
return this.recentlyStartedThreshold;
}
public void setRecentlyStartedThreshold(int recentlyStartedThreshold)
{
this.recentlyStartedThreshold = recentlyStartedThreshold;
}
public long getOverloadWithoutRefusalLifetime()
{
return this.overloadWithoutRefusalLifetime;
}
public void setOverloadWithoutRefusalLifetime(int overloadWithoutRefusalLifetime)
{
this.overloadWithoutRefusalLifetime = overloadWithoutRefusalLifetime;
}
public long getMaximumActiveTime()
{
return this.maximumActiveTime;
}
public void setMaximumActiveTime(long maximumActiveTime)
{
this.maximumActiveTime = maximumActiveTime;
}
public boolean isVerbose()
{
return this.verbose;
}
public void setVerbose(boolean verbose)
{
this.verbose = verbose;
}
public boolean isTrace()
{
return this.trace;
}
public void setTrace(boolean trace)
{
this.trace = trace;
}
public String getStatistics()
{
return this.statistics;
}
public void setStatistics(String statistics)
{
this.statistics = statistics;
}
public String getStatisticsLogLevel()
{
return this.statisticsLogLevel;
}
public void setStatisticsLogLevel(String statisticsLogLevel)
{
this.statisticsLogLevel = statisticsLogLevel;
}
public String getFatalSqlExceptionsAsString()
{
return this.fatalSqlExceptionsAsString;
}
public void setFatalSqlExceptionsAsString(String fatalSqlExceptionsAsString)
{
this.fatalSqlExceptionsAsString = fatalSqlExceptionsAsString;
}
public String getFatalSqlExceptionWrapperClass()
{
return this.fatalSqlExceptionWrapperClass;
}
public void setFatalSqlExceptionWrapperClass(String fatalSqlExceptionWrapperClass)
{
this.fatalSqlExceptionWrapperClass = fatalSqlExceptionWrapperClass;
}
public String getHouseKeepingTestSql()
{
return this.houseKeepingTestSql;
}
public void setHouseKeepingTestSql(String houseKeepingTestSql)
{
this.houseKeepingTestSql = houseKeepingTestSql;
}
public String getUser()
{
return this.user;
}
public void setUser(String user)
{
this.user = user;
}
public String getPassword()
{
return this.password;
}
public void setPassword(String password)
{
this.password = password;
}
public boolean isJmx()
{
return this.jmx;
}
public void setJmx(boolean jmx)
{
this.jmx = jmx;
}
public String getJmxAgentId()
{
return this.jmxAgentId;
}
public void setJmxAgentId(String jmxAgentId)
{
this.jmxAgentId = jmxAgentId;
}
public boolean isTestBeforeUse()
{
return this.testBeforeUse;
}
public void setTestBeforeUse(boolean testBeforeUse)
{
this.testBeforeUse = testBeforeUse;
}
public boolean isTestAfterUse()
{
return this.testAfterUse;
}
public void setTestAfterUse(boolean testAfterUse)
{
this.testAfterUse = testAfterUse;
}
public void setDelegateProperties(String properties)
{
StringTokenizer stOuter = new StringTokenizer(properties, ",");
while (stOuter.hasMoreTokens()) {
StringTokenizer stInner = new StringTokenizer(stOuter.nextToken(), "=");
if (stInner.countTokens() == 1)
{
this.delegateProperties.put(stInner.nextToken().trim(), "");
} else if (stInner.countTokens() == 2)
this.delegateProperties.put(stInner.nextToken().trim(), stInner.nextToken().trim());
else
throw new IllegalArgumentException("Unexpected delegateProperties value: '" + properties + "'. Expected 'name=value'");
}
}
private void populatePropertiesFromReference(Reference reference)
{
RefAddr property = reference.get("proxool.alias");
if (property != null) {
setAlias(property.getContent().toString());
}
property = reference.get("proxool.driver-class");
if (property != null) {
setDriver(property.getContent().toString());
}
property = reference.get("proxool.fatal-sql-exception-wrapper-class");
if (property != null) {
setFatalSqlExceptionWrapperClass(property.getContent().toString());
}
property = reference.get("proxool.house-keeping-sleep-time");
if (property != null) {
setHouseKeepingSleepTime(Integer.valueOf(property.getContent().toString()).intValue());
}
property = reference.get("proxool.house-keeping-test-sql");
if (property != null) {
setHouseKeepingTestSql(property.getContent().toString());
}
property = reference.get("proxool.maximum-connection-count");
if (property != null) {
setMaximumConnectionCount(Integer.valueOf(property.getContent().toString()).intValue());
}
property = reference.get("proxool.maximum-connection-lifetime");
if (property != null) {
setMaximumConnectionLifetime(Integer.valueOf(property.getContent().toString()).intValue());
}
property = reference.get("proxool.maximum-active-time");
if (property != null) {
setMaximumActiveTime(Long.valueOf(property.getContent().toString()).intValue());
}
property = reference.get("proxool.minimum-connection-count");
if (property != null) {
setMinimumConnectionCount(Integer.valueOf(property.getContent().toString()).intValue());
}
property = reference.get("proxool.overload-without-refusal-lifetime");
if (property != null) {
setOverloadWithoutRefusalLifetime(Integer.valueOf(property.getContent().toString()).intValue());
}
property = reference.get("password");
if (property != null) {
setPassword(property.getContent().toString());
}
property = reference.get("proxool.prototype-count");
if (property != null) {
setPrototypeCount(Integer.valueOf(property.getContent().toString()).intValue());
}
property = reference.get("proxool.recently-started-threshold");
if (property != null) {
setRecentlyStartedThreshold(Integer.valueOf(property.getContent().toString()).intValue());
}
property = reference.get("proxool.simultaneous-build-throttle");
if (property != null) {
setSimultaneousBuildThrottle(Integer.valueOf(property.getContent().toString()).intValue());
}
property = reference.get("proxool.statistics");
if (property != null) {
setStatistics(property.getContent().toString());
}
property = reference.get("proxool.statistics-log-level");
if (property != null) {
setStatisticsLogLevel(property.getContent().toString());
}
property = reference.get("proxool.trace");
if (property != null) {
setTrace("true".equalsIgnoreCase(property.getContent().toString()));
}
property = reference.get("proxool.driver-url");
if (property != null) {
setDriverUrl(property.getContent().toString());
}
property = reference.get("user");
if (property != null) {
setUser(property.getContent().toString());
}
property = reference.get("proxool.verbose");
if (property != null) {
setVerbose("true".equalsIgnoreCase(property.getContent().toString()));
}
property = reference.get("proxool.jmx");
if (property != null) {
setJmx("true".equalsIgnoreCase(property.getContent().toString()));
}
property = reference.get("proxool.jmx-agent-id");
if (property != null) {
setJmxAgentId(property.getContent().toString());
}
property = reference.get("proxool.test-before-use");
if (property != null) {
setTestBeforeUse("true".equalsIgnoreCase(property.getContent().toString()));
}
property = reference.get("proxool.test-after-use");
if (property != null) {
setTestAfterUse("true".equalsIgnoreCase(property.getContent().toString()));
}
Enumeration e = reference.getAll();
while (e.hasMoreElements()) {
StringRefAddr stringRefAddr = (StringRefAddr)e.nextElement();
String name = stringRefAddr.getType();
String content = stringRefAddr.getContent().toString();
if (name.indexOf("proxool.") != 0)
this.delegateProperties.put(name, content);
}
}
private void reset()
{
this.driverUrl = null;
this.driver = null;
this.maximumConnectionLifetime = 14400000L;
this.prototypeCount = 0;//
this.minimumConnectionCount = 0;//最小链接数
this.maximumConnectionCount = 15;//最大链接数
this.houseKeepingSleepTime = 30000L;
this.houseKeepingTestSql = null;
this.simultaneousBuildThrottle = 10;
this.recentlyStartedThreshold = 60000L;//
this.overloadWithoutRefusalLifetime = 60000L;//
this.maximumActiveTime = 300000L;
this.verbose = false;
this.trace = false;
this.statistics = null;
this.statisticsLogLevel = null;
this.delegateProperties.clear();
}
public PrintWriter getLogWriter() throws SQLException {
return this.logWriter;
}
public int getLoginTimeout() throws SQLException {
return this.loginTimeout;
}
public void setLogWriter(PrintWriter logWriter) throws SQLException {
this.logWriter = logWriter;
}
public void setLoginTimeout(int loginTimeout) throws SQLException {
this.loginTimeout = loginTimeout;
}
public Connection getConnection(String s, String s1) throws SQLException {
throw new UnsupportedOperationException("You should configure the username and password within the proxool configuration and just call getConnection() instead.");
}
}
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Properties;
import java.util.StringTokenizer;
import javax.naming.Context;
import javax.naming.Name;
import javax.naming.RefAddr;
import javax.naming.Reference;
import javax.naming.StringRefAddr;
import javax.naming.spi.ObjectFactory;
import javax.sql.DataSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class ProxoolDataSource
implements DataSource, ObjectFactory
{
private static final Log LOG = LogFactory.getLog(ProxoolDataSource.class);
private int loginTimeout;
private PrintWriter logWriter;
private String alias;//是连接池的别名
private String driver;//数据库驱动
private String fatalSqlExceptionWrapperClass;
private long houseKeepingSleepTime;//保留线程处于睡眠状态的最长时间,house keeper 的职责就是检查各个连接的状态,并判断是否需要销毁或者创建.
//自动侦察各个连接状态的时间间隔(毫秒),侦察到空闲的连接就马上回收,超时的销毁 默认30秒,视乎不允许被赋值;
private String houseKeepingTestSql;// 如果发现了空闲的数据库连接.house keeper 将会用这个语句来测试.这个语句最好非常快的被执行.如果没有定义,测试过程将会被忽略。
private long maximumActiveTime;//如果housekeeper 检测到某个线程的活动时间大于这个数值.它将会杀掉这个线程.所以确认一下你的服务器的带宽.然后定一个合适的值.默认是5分钟
private int maximumConnectionCount;//最大连接数
private long maximumConnectionLifetime;//一个线程的最大寿命.
private int minimumConnectionCount;//最小链接数
private long overloadWithoutRefusalLifetime;//这可以帮助我们确定连接池的状态。如果我们已经拒绝了一个连接在这个设定值(毫秒),然后被认为是超载。默认为60秒。
private String password;//数据库密码
private int prototypeCount;//最少保持的空闲连接数 (默认5个)-->
private long recentlyStartedThreshold;//这可以帮助我们确定连接池的状态,连接数少还是多或超载。只要至少有一个连接已开始在此值(毫秒)内,或者有一些多余的可用连接,那么我们假设连接池是开启的。默认为60秒
private int simultaneousBuildThrottle;//这是我们可一次建立的最大连接数。那就是新增的连接请求,但还没有可供使用的连接。由于连接可以使用多线程,在有限的时间之间建立联系从而带来可用连接,但是我们需要通过一些方式确认一些线程并不是立即响应连接请求的,默认是10。
private String statistics;//连接池使用状况统计。 参数“10s,1m,1d”
private String statisticsLogLevel;//日志统计跟踪类型。 参数“ERROR”或 “INFO”
private boolean trace;// 如果为true,那么每个被执行的SQL语句将会在执行期被log记录(DEBUG LEVEL).你也可以注册一个ConnectionListener (参看ProxoolFacade)得到这些信息.
private String driverUrl;//数据库链接字符串
private String user;//数据库用户名
private boolean verbose;
private boolean jmx;
private String jmxAgentId;
private boolean testBeforeUse;//如果为true,在每个连接被测试前都会服务这个连接,如果一个连接失败,那么将被丢弃,另一个连接将会被处理,如果所有连接都失败,一个新的连接将会被建立。否则将会抛出一个SQLException异常。
private boolean testAfterUse;//如果为true,在每个连接被测试后都会服务这个连接,使其回到连接池中,如果连接失败,那么将被废弃
private Properties delegateProperties = new Properties();
private String fatalSqlExceptionsAsString;
public ProxoolDataSource()
{
reset();
}
public ProxoolDataSource(String alias) {
this.alias = alias;
}
public Connection getConnection()
throws SQLException
{
ConnectionPool cp = null;
try {
if (!ConnectionPoolManager.getInstance().isPoolExists(this.alias)) {
registerPool();
}
cp = ConnectionPoolManager.getInstance().getConnectionPool(this.alias);
return cp.getConnection();
} catch (ProxoolException e) {
LOG.error("Problem getting connection", e);
}throw new SQLException(e.toString());
}
private synchronized void registerPool()
throws ProxoolException
{
if (!ConnectionPoolManager.getInstance().isPoolExists(this.alias)) {
ConnectionPoolDefinition cpd = new ConnectionPoolDefinition();
cpd.setAlias(getAlias());
cpd.setDriver(getDriver());
cpd.setFatalSqlExceptionsAsString(getFatalSqlExceptionsAsString());
cpd.setFatalSqlExceptionWrapper(getFatalSqlExceptionWrapperClass());
cpd.setHouseKeepingSleepTime(getHouseKeepingSleepTime());
cpd.setHouseKeepingTestSql(getHouseKeepingTestSql());
cpd.setMaximumActiveTime(getMaximumActiveTime());
cpd.setMaximumConnectionCount(getMaximumConnectionCount());
cpd.setMaximumConnectionLifetime(getMaximumConnectionLifetime());
cpd.setMinimumConnectionCount(getMinimumConnectionCount());
cpd.setOverloadWithoutRefusalLifetime(getOverloadWithoutRefusalLifetime());
cpd.setPrototypeCount(getPrototypeCount());
cpd.setRecentlyStartedThreshold(getRecentlyStartedThreshold());
cpd.setSimultaneousBuildThrottle(getSimultaneousBuildThrottle());
cpd.setStatistics(getStatistics());
cpd.setStatisticsLogLevel(getStatisticsLogLevel());
cpd.setTrace(isTrace());
cpd.setUrl(getDriverUrl());
cpd.setVerbose(isVerbose());
cpd.setJmx(isJmx());
cpd.setJmxAgentId(getJmxAgentId());
cpd.setTestAfterUse(isTestAfterUse());
cpd.setTestBeforeUse(isTestBeforeUse());
cpd.setDelegateProperties(this.delegateProperties);
cpd.setUser(getUser());
cpd.setPassword(getPassword());
ProxoolFacade.registerConnectionPool(cpd);
}
}
public Object getObjectInstance(Object refObject, Name name, Context context, Hashtable hashtable)
throws Exception
{
if (!(refObject instanceof Reference)) {
return null;
}
Reference reference = (Reference)refObject;
if (!ConnectionPoolManager.getInstance().isPoolExists(reference.get("proxool.alias").toString())) {
populatePropertiesFromReference(reference);
}
return this;
}
public String getAlias()
{
return this.alias;
}
public void setAlias(String alias)
{
this.alias = alias;
}
public String getDriverUrl()
{
return this.driverUrl;
}
public void setDriverUrl(String url)
{
this.driverUrl = url;
}
public String getDriver()
{
return this.driver;
}
public void setDriver(String driver)
{
this.driver = driver;
}
public long getMaximumConnectionLifetime()
{
return this.maximumConnectionLifetime;
}
public void setMaximumConnectionLifetime(int maximumConnectionLifetime)
{
this.maximumConnectionLifetime = maximumConnectionLifetime;
}
public int getPrototypeCount()
{
return this.prototypeCount;
}
public void setPrototypeCount(int prototypeCount)
{
this.prototypeCount = prototypeCount;
}
public int getMinimumConnectionCount()
{
return this.minimumConnectionCount;
}
public void setMinimumConnectionCount(int minimumConnectionCount)
{
this.minimumConnectionCount = minimumConnectionCount;
}
public int getMaximumConnectionCount()
{
return this.maximumConnectionCount;
}
public void setMaximumConnectionCount(int maximumConnectionCount)
{
this.maximumConnectionCount = maximumConnectionCount;
}
public long getHouseKeepingSleepTime()
{
return this.houseKeepingSleepTime;
}
public void setHouseKeepingSleepTime(int houseKeepingSleepTime)
{
this.houseKeepingSleepTime = houseKeepingSleepTime;
}
public int getSimultaneousBuildThrottle()
{
return this.simultaneousBuildThrottle;
}
public void setSimultaneousBuildThrottle(int simultaneousBuildThrottle)
{
this.simultaneousBuildThrottle = simultaneousBuildThrottle;
}
public long getRecentlyStartedThreshold()
{
return this.recentlyStartedThreshold;
}
public void setRecentlyStartedThreshold(int recentlyStartedThreshold)
{
this.recentlyStartedThreshold = recentlyStartedThreshold;
}
public long getOverloadWithoutRefusalLifetime()
{
return this.overloadWithoutRefusalLifetime;
}
public void setOverloadWithoutRefusalLifetime(int overloadWithoutRefusalLifetime)
{
this.overloadWithoutRefusalLifetime = overloadWithoutRefusalLifetime;
}
public long getMaximumActiveTime()
{
return this.maximumActiveTime;
}
public void setMaximumActiveTime(long maximumActiveTime)
{
this.maximumActiveTime = maximumActiveTime;
}
public boolean isVerbose()
{
return this.verbose;
}
public void setVerbose(boolean verbose)
{
this.verbose = verbose;
}
public boolean isTrace()
{
return this.trace;
}
public void setTrace(boolean trace)
{
this.trace = trace;
}
public String getStatistics()
{
return this.statistics;
}
public void setStatistics(String statistics)
{
this.statistics = statistics;
}
public String getStatisticsLogLevel()
{
return this.statisticsLogLevel;
}
public void setStatisticsLogLevel(String statisticsLogLevel)
{
this.statisticsLogLevel = statisticsLogLevel;
}
public String getFatalSqlExceptionsAsString()
{
return this.fatalSqlExceptionsAsString;
}
public void setFatalSqlExceptionsAsString(String fatalSqlExceptionsAsString)
{
this.fatalSqlExceptionsAsString = fatalSqlExceptionsAsString;
}
public String getFatalSqlExceptionWrapperClass()
{
return this.fatalSqlExceptionWrapperClass;
}
public void setFatalSqlExceptionWrapperClass(String fatalSqlExceptionWrapperClass)
{
this.fatalSqlExceptionWrapperClass = fatalSqlExceptionWrapperClass;
}
public String getHouseKeepingTestSql()
{
return this.houseKeepingTestSql;
}
public void setHouseKeepingTestSql(String houseKeepingTestSql)
{
this.houseKeepingTestSql = houseKeepingTestSql;
}
public String getUser()
{
return this.user;
}
public void setUser(String user)
{
this.user = user;
}
public String getPassword()
{
return this.password;
}
public void setPassword(String password)
{
this.password = password;
}
public boolean isJmx()
{
return this.jmx;
}
public void setJmx(boolean jmx)
{
this.jmx = jmx;
}
public String getJmxAgentId()
{
return this.jmxAgentId;
}
public void setJmxAgentId(String jmxAgentId)
{
this.jmxAgentId = jmxAgentId;
}
public boolean isTestBeforeUse()
{
return this.testBeforeUse;
}
public void setTestBeforeUse(boolean testBeforeUse)
{
this.testBeforeUse = testBeforeUse;
}
public boolean isTestAfterUse()
{
return this.testAfterUse;
}
public void setTestAfterUse(boolean testAfterUse)
{
this.testAfterUse = testAfterUse;
}
public void setDelegateProperties(String properties)
{
StringTokenizer stOuter = new StringTokenizer(properties, ",");
while (stOuter.hasMoreTokens()) {
StringTokenizer stInner = new StringTokenizer(stOuter.nextToken(), "=");
if (stInner.countTokens() == 1)
{
this.delegateProperties.put(stInner.nextToken().trim(), "");
} else if (stInner.countTokens() == 2)
this.delegateProperties.put(stInner.nextToken().trim(), stInner.nextToken().trim());
else
throw new IllegalArgumentException("Unexpected delegateProperties value: '" + properties + "'. Expected 'name=value'");
}
}
private void populatePropertiesFromReference(Reference reference)
{
RefAddr property = reference.get("proxool.alias");
if (property != null) {
setAlias(property.getContent().toString());
}
property = reference.get("proxool.driver-class");
if (property != null) {
setDriver(property.getContent().toString());
}
property = reference.get("proxool.fatal-sql-exception-wrapper-class");
if (property != null) {
setFatalSqlExceptionWrapperClass(property.getContent().toString());
}
property = reference.get("proxool.house-keeping-sleep-time");
if (property != null) {
setHouseKeepingSleepTime(Integer.valueOf(property.getContent().toString()).intValue());
}
property = reference.get("proxool.house-keeping-test-sql");
if (property != null) {
setHouseKeepingTestSql(property.getContent().toString());
}
property = reference.get("proxool.maximum-connection-count");
if (property != null) {
setMaximumConnectionCount(Integer.valueOf(property.getContent().toString()).intValue());
}
property = reference.get("proxool.maximum-connection-lifetime");
if (property != null) {
setMaximumConnectionLifetime(Integer.valueOf(property.getContent().toString()).intValue());
}
property = reference.get("proxool.maximum-active-time");
if (property != null) {
setMaximumActiveTime(Long.valueOf(property.getContent().toString()).intValue());
}
property = reference.get("proxool.minimum-connection-count");
if (property != null) {
setMinimumConnectionCount(Integer.valueOf(property.getContent().toString()).intValue());
}
property = reference.get("proxool.overload-without-refusal-lifetime");
if (property != null) {
setOverloadWithoutRefusalLifetime(Integer.valueOf(property.getContent().toString()).intValue());
}
property = reference.get("password");
if (property != null) {
setPassword(property.getContent().toString());
}
property = reference.get("proxool.prototype-count");
if (property != null) {
setPrototypeCount(Integer.valueOf(property.getContent().toString()).intValue());
}
property = reference.get("proxool.recently-started-threshold");
if (property != null) {
setRecentlyStartedThreshold(Integer.valueOf(property.getContent().toString()).intValue());
}
property = reference.get("proxool.simultaneous-build-throttle");
if (property != null) {
setSimultaneousBuildThrottle(Integer.valueOf(property.getContent().toString()).intValue());
}
property = reference.get("proxool.statistics");
if (property != null) {
setStatistics(property.getContent().toString());
}
property = reference.get("proxool.statistics-log-level");
if (property != null) {
setStatisticsLogLevel(property.getContent().toString());
}
property = reference.get("proxool.trace");
if (property != null) {
setTrace("true".equalsIgnoreCase(property.getContent().toString()));
}
property = reference.get("proxool.driver-url");
if (property != null) {
setDriverUrl(property.getContent().toString());
}
property = reference.get("user");
if (property != null) {
setUser(property.getContent().toString());
}
property = reference.get("proxool.verbose");
if (property != null) {
setVerbose("true".equalsIgnoreCase(property.getContent().toString()));
}
property = reference.get("proxool.jmx");
if (property != null) {
setJmx("true".equalsIgnoreCase(property.getContent().toString()));
}
property = reference.get("proxool.jmx-agent-id");
if (property != null) {
setJmxAgentId(property.getContent().toString());
}
property = reference.get("proxool.test-before-use");
if (property != null) {
setTestBeforeUse("true".equalsIgnoreCase(property.getContent().toString()));
}
property = reference.get("proxool.test-after-use");
if (property != null) {
setTestAfterUse("true".equalsIgnoreCase(property.getContent().toString()));
}
Enumeration e = reference.getAll();
while (e.hasMoreElements()) {
StringRefAddr stringRefAddr = (StringRefAddr)e.nextElement();
String name = stringRefAddr.getType();
String content = stringRefAddr.getContent().toString();
if (name.indexOf("proxool.") != 0)
this.delegateProperties.put(name, content);
}
}
private void reset()
{
this.driverUrl = null;
this.driver = null;
this.maximumConnectionLifetime = 14400000L;
this.prototypeCount = 0;//
this.minimumConnectionCount = 0;//最小链接数
this.maximumConnectionCount = 15;//最大链接数
this.houseKeepingSleepTime = 30000L;
this.houseKeepingTestSql = null;
this.simultaneousBuildThrottle = 10;
this.recentlyStartedThreshold = 60000L;//
this.overloadWithoutRefusalLifetime = 60000L;//
this.maximumActiveTime = 300000L;
this.verbose = false;
this.trace = false;
this.statistics = null;
this.statisticsLogLevel = null;
this.delegateProperties.clear();
}
public PrintWriter getLogWriter() throws SQLException {
return this.logWriter;
}
public int getLoginTimeout() throws SQLException {
return this.loginTimeout;
}
public void setLogWriter(PrintWriter logWriter) throws SQLException {
this.logWriter = logWriter;
}
public void setLoginTimeout(int loginTimeout) throws SQLException {
this.loginTimeout = loginTimeout;
}
public Connection getConnection(String s, String s1) throws SQLException {
throw new UnsupportedOperationException("You should configure the username and password within the proxool configuration and just call getConnection() instead.");
}
}
发表评论
-
各数据库分页sql备忘
2014-12-17 20:45 1123ORACLE 下面这个效率很低 SELECT * FROM ( ... -
mysql字符串与日期类型互转
2014-03-30 17:53 60624小时格式 select str_to_date('2014 ... -
sql优化笔记(个人知识积累备忘录)
2012-09-23 18:05 1091未完待续 数据库连接池是针对于一台数据库来说的还是对于一个数 ... -
linux下安装oracle11g步骤与体会
2011-05-01 10:14 114409年掌上城市开发经验 ... -
Oracle Pack用法详解
2011-05-01 09:57 1226Oracle Package有哪些作用呢? 简化应用设计、提 ... -
join用法
2011-04-28 15:42 725条件连接(join) T1 { [INNER] | { LE ... -
Oracle Group By 用法之 —— Having
2011-04-28 15:35 2804客户需求分析: ... -
oracle游标使用详解
2011-04-27 19:59 1167游标(CURSOR)也叫光标,在关系数据库中经常使用,在PL/ ...
相关推荐
jar包,官方版本,自测可用
proxool-0.9.1.jar包是一个数据库连接池包,最新版解决前几个版本里在二次关闭一个rs集的时候警告等一些bug。proxool-0.9.1.jar监控在对中文监控出现乱码情况做了更改。具体是对org.logicalcobwebs.proxool.admin....
proxool.0.9.1基础上做了修改。 改jar名称为:proxool-0.9.1.1,主要修改为以下3点: 1.解决不能Unregister jdbc driver的内存泄露问题。 十二月 02, 2013 8:19:43 上午 org.apache.catalina.loader....
Proxool是一个开源的、轻量级的Java数据库连接池实现,它提供了一种高效、灵活的方式来管理数据库连接。在某些场景下,为了保护敏感信息,如数据库的用户名和密码,我们需要对这些数据进行加密处理。"proxool连接池...
方法是将org.logicalcobwebs.proxool.ProxoolDataSource 中houseKeepingSleepTime,maximumConnectionLifetime,recentlyStartedThreshold,recentlyStartedThreshold 中对应的set方法传入的类型从int改成long型。
implementation 'org.logicalcobwebs.proxool:proxool:0.9.1' ``` 2. **配置Proxool**:在项目的配置文件(如`proxool.properties`)中设置Proxool的参数,例如: ``` proxool.mysql.driver-url=jdbc:mysql://...
下载完成后,需要将两个JAR包:`proxool-0.9.1.jar` 和 `proxool-cglib.jar` 以及 `commons-logging.jar` 复制到项目的 `lib` 文件夹下。这三个库文件是Proxool正常运行所必需的基础依赖。 **2. 创建并配置`proxool...
当前最新版本为0.9.1,解压后将`lib`目录下的两个JAR包`proxool-0.9.1.jar`和`proxool-cglib.jar`添加到项目的类路径中。如果没有加入`proxool-cglib.jar`,可能会遇到`java.lang.ClassNotFoundException: org....
同时,我们需要导入Proxool连接池的相关库,包括`proxool-0.9.1.jar`,`proxool-cglib.jar`,以及对应的数据库驱动包(这里是`mysql-connector-java-5.0.8-bin.jar`)。 在项目中,我们需要创建一个名为`jdbc....
对于数据库连接池,这里使用了Proxool,需要导入proxool-0.9.1.jar和proxool-cglib.jar。同时,由于使用MySQL数据库,还需要导入对应的驱动包,例如mysql-connector-java-5.0.8-bin.jar。 配置数据库连接信息通常是...
- 导入必要的JAR包:`proxool-0.9.1.jar`, `proxool-cglib.jar`, `mysql-connector-java-5.0.8-bin.jar`。 - 编写`src/jdbc.properties`文件,定义数据库连接参数,如: ```properties db.driver=...
3. **配置数据库连接池**:这里使用的是Proxool,导入`proxool-0.9.1.jar`和`proxool-cglib.jar`。然后在src目录下创建`jdbc.properties`文件,配置数据库连接参数,如驱动、URL、用户名、密码等。 4. **整合Spring...