代考首页 | 代考价格 | 代考流程 | 证书查询 | 信誉评价 | 代考论坛 | 海外港台代考价格 | 题库报价
  思科CISCO | 微软MICROSOFT | 华为HCNE | ORACLE认证 | SUN认证 | CIW认证 | IBM认证 | LPI认证 | CCNA专题 | MCSE专题 | ADOBE | 仿真题库
   会员登陆
用户:
密码:

   代考详细流程

代考地图
代考思科CCNA认证
代考思科CCNP认证
代考微软MCP认证
代考微软MCSE2000
代考微软MCSE2003
代考微软MCSD.NET
代考LPI认证
代考微软全能认证
代考思科微软全能认证
代考思科全能认证
代考思科CCDA认证
代考思科CCDP认证
代考思科CCIP认证
代考思科CCSP认证
代考思科CCVP认证
代考微软MCTS技术专家
代考MCITP微软IT专家
代考MCPD专业开发人员

   IT代考--本站服务
  itsky100.comIT认证代考 联盟的 代考 机构,提供 CCNA 代考 ,MCSE 代考 ,MCP 代考 ,CCNP 代考 ,JAVA 代考 ,ORACLE 代考 等各种IT 认证替考 服务。
  免费提供 IT认证 学习资料 考试题库 CCNA CCNP JAVA CIW MCSE MCSD教学资料 免费下载。
  IT认证代考 ,具体操作在我们的考试中心进行,通过百分百,请您绝对放心。
 
 
 
 
 
 
  首页>>SUN认证>>正文
 
超级简单的数据库连接池
连接池最基本的目的: 
1、重用连接,节省连接资源; 
2、免去建立连接操作,提高效率
3. 限制最大连接并发数


自己弄的一个连接池,绝对高效安全,支持多数据源


连接池的两种实现方式:

1. 修饰模式弄个ConnectionWrapper类出来 
2. 动态代理


这里采用的是第一种方式



ConnectionAdapter  implements Connetion
ConnectionWrapper extends ConnectionAdapter 

ConnectionWrapper 中封装了connection对象
close方法重写为
{
 SimpleConnectionPool.putConnectionToPool(this);
 //把连接返回连接池
}


配置文件 app.properties


ConnectionAdapter 从DBCP拷贝过来,删了些垃圾东西

支持多数据源

DBUtil.getConn();//获取默认连接池
DBUtil.getConn(pool_name);//获取指定名称的连接池



各参数说明

pool_name.dirver

driver=net.sourceforge.jtds.jdbc.Driver
url=jdbc:jtds:sqlserver://127.0.0.1:1433/data
user=sa
pwd=sa
type=sqlserver //数据库类型
pool=1        //是否使用连接池 1 使用
max_wait=3    //连接池已满时,最大等待时间 ,单位 s
#timeout ,wait time when max active ,  unit s
max_active=20  //最大活动连接数,用这个来控制最大并发数
min_free=3     //连接池中最小空闲连接数
max_free=20    //连接池中最大空闲连接数,默认=max_active
check_sql=select getdate()  //验证连接是否有效,
clear_time=2                //清理空闲连接
#clear_time,remove the old connection,unit min




还可以用动态代理的方式实现连接池


2.

动态代理实现



class ConnectionWrapper implements InvocationHandler {

private final static String CLOSE_METHOD_NAME = "close";
  public Connection connection = null;
  private Connection m_originConnection = null;

 ConnectionWrapper(Connection con,String pool_name)throws Exception {
    this.pool_name=pool_name;
    
    this.check_sql = getCheckSqlByPoolName(pool_name);
    
    last_use_time = System.currentTimeMillis();
    create = StringUtil.getNowTime()+"";
    
      Class[] interfaces = {java.sql.Connection.class};
    this.connection = (Connection) Proxy.newProxyInstance(
      con.getClass().getClassLoader(),
      interfaces, this);
    m_originConnection = con;
  }

  
  void close() {
    //m_originConnection.close();
      DBUtil.close(m_originConnection);
  }

  public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {

本新闻共2页,当前在第1页  1  2  

 

 

版权所有 国际IT认证代考联盟网

Copyright (C) 2006 www.ITSKY100.com All rights reserved