//ConnObj *co = ConnPool::GetInstance()->GetConn();
//_ConnectionPtr m_pConnection = co->conn;
#pragma once
#include <stdio.h>
#include <string>
#include <list>
#include <iostream>
#import "c:\Program Files\Common Files\System\ADO\msado15.dll" no_namespace rename("EOF", "adoEOF")
#include "ConnObj.h"
using namespace std;
class ConnPool
{
private:
static ConnPool* cpInst;
public:
list<ConnObj*> poolList;
public:
static ConnPool* GetInstance();
void Init();
ConnObj* Increase();
ConnObj* GetConn();
void DropConn(ConnObj* co);
public:
ConnPool(void);
~ConnPool(void);
};
#include "StdAfx.h"
#include "ConnPool.h"
#include <algorithm>
#define MIN_COUNT 10
#define MAX_COUNT 100
HANDLE hMutex;
ConnPool::ConnPool(void)
{
this->Init();
}
ConnPool::~ConnPool(void)
{
}
ConnPool* ConnPool::cpInst = NULL;
ConnPool* ConnPool::GetInstance()
{
if(NULL==cpInst)
{
cpInst = new ConnPool();
}
else
{
return cpInst;
}
}
void ConnPool::Init()
{
CoInitialize(NULL);
for(int i=0;i<MIN_COUNT;i++)
{
ConnObj *co = new ConnObj;
co->OpenConn();
if(NULL!=co)
{
//lock
WaitForSingleObject(hMutex,INFINITE);
poolList.push_back(co);
ReleaseMutex(hMutex);
}
}
}
ConnObj* ConnPool::Increase()
{
int size = poolList.size();
if(size<MAX_COUNT)
{
ConnObj *co = new ConnObj;
co->OpenConn();
if(NULL!=co)
{
//lock
WaitForSingleObject(hMutex,INFINITE);
poolList.push_back(co);
ReleaseMutex(hMutex);
return co;
}
else
{
return NULL;
}
}
else
{
return NULL;
}
}
ConnObj* ConnPool::GetConn()
{
bool bSuc;
for(list<ConnObj*>::iterator it = this->poolList.begin();it!=this->poolList.end();it++)
{
if(!(*it)->isUsed)
{
WaitForSingleObject(hMutex,INFINITE);
(*it)->isUsed = true;
(*it)->usedCount = (*it)->usedCount + 1;
ReleaseMutex(hMutex);
bSuc = true;
return (*it);
break;
}
}
//全满
if(!bSuc)
{
return Increase();
}
}
void ConnPool::DropConn(ConnObj* co)
{
co->isUsed = false;
co->usedCount = co->usedCount - 1;
}
相关推荐
1DM 集群代理简介 1 2体系架构 2 3功能模块管理 3 ...5.4V$DCP_CONNPOOL 9 6典型案例 10 6.1经典情景一:普通 MPP 环境 10 6.2经典情景二:MPP 主备环境 14 6.3经典情景三:多个 DCP 同时提供服务 32
logDir =logs/connPool debug = false } DatabaseProfile { Oracle { driverClass = oracle.jdbc.driver.OracleDriver dbUrl = jdbc:oracle:thin:@192.168.0.108:1521:oracle dbUser = tester dbPass = tester ...
<jsp:useBean id="pool" scope="application" class="chapter10.ConnPool"/> boolean success=true; boolean disable=false; String name=new String(request.getParameter("name").getBytes("ISO8859_1"),"GBK"); ...
webservice webmail workflow connpool socket 以上项目的实例源码
① ConnectionPool connPool = new ConnectionPool("org.postgresql.Driver" ,"jdbc:postgresql://dbURI:5432/DBName" ,"postgre","postgre"); ② connPool .createPool(); Connection conn = connPool .get...
主要介绍了Java连接数据库oracle中文乱码解决方案,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
Client和ConnPool基于dvirsky和mnunberg在上的工作正在安装$ go get github.com/RedisTimeSeries/redistimeseries-go运行测试提供了一个简单的测试套件,可以与以下程序一起运行: $ go test 测试期望加载了...
用nodejs语言、http协议、mysql做数据库写的web服务器,这个是学习的时候自己跟着老师做的,数据库表在F:\workspace_Webstorm\segment\models\ConnPool.js里面,可以直接复制黏贴建表。
// configure the Netty's bootstrap instance here// your custom channel pool handlerfinal ChannelPoolHandler cph = ...final NonBlockingConnPool connPool = new BasicMultiNodeConnPool(
连接池设计文档,大家可以参考