数据库连接池Java实现小结

http://tech.ddvip.com   2006年11月25日    社区交流

本文详细介绍数据库连接池Java实现小结

/*
* Created on 2003-5-13
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package scut.ailab.connectionpool;
/**
* @author youyongming
*
*/
//连接池调度线程
public class FactoryMangeThread implements Runnable {
ConnectionFactory cf = null;
long delay = 1000;
public FactoryMangeThread(ConnectionFactory obj)
{
 cf = obj;
}
/* (non-Javadoc)
 * @see java.lang.Runnable#run()
 */
public void run() {
 while(true){
 try{
  Thread.sleep(delay);
 }
 catch(InterruptedException e){}
 System.out.println("eeeee");
 //判断是否已经关闭了工厂,那就退出监听
 if (cf.isCreate())
  cf.schedule();
 else
  System.exit(1);
 }
}
}

  FactoryParam.java

/*
* Created on 2003-5-13
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package scut.ailab.connectionpool;
/**
* @author youyongming
*
*/
//连接池工厂参数
public class FactoryParam {
//最大连接数
private int MaxConnectionCount = 4;
//最小连接数
private int MinConnectionCount = 2;
//回收策略
private int ManageType = 0;
public FactoryParam(){
}
/**
 * 构造连接池工厂参数的对象
 * @param max最大连接数
 * @param min最小连接数
 * @param type管理策略
 */
public FactoryParam(int max, int min, int type)
{
 this.ManageType = type;
 this.MaxConnectionCount = max;
 this.MinConnectionCount = min;
}
/**
 * 设置最大的连接数
 * @param value
 */
public void setMaxConn(int value)
{
 this.MaxConnectionCount = value;
}
/**
 * 获取最大连接数
 * @return
 */
public int getMaxConn()
{
 return this.MaxConnectionCount;
}
/**
 * 设置最小连接数
 * @param value
 */
public void setMinConn(int value)
{
 this.MinConnectionCount = value;
}
/**
 * 获取最小连接数
 * @return
 */
public int getMinConn()
{
 return this.MinConnectionCount;
}
public int getType()
{
 return this.ManageType;
}
}

  testmypool.java

责编:豆豆技术应用

正在加载评论...