2019-07-28 10:31:56 +08:00
|
|
|
#include "stdafx.h"
|
2013-08-18 17:42:25 +08:00
|
|
|
|
|
|
|
using namespace acl;
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
db_pool *dp = new mysql_pool("127.0.0.1:3306", "test_db", "zsxxsz",
|
|
|
|
"111111");
|
|
|
|
|
|
|
|
std::list<db_handle*> dbs;
|
|
|
|
|
2019-07-28 10:31:56 +08:00
|
|
|
// 设置空闲连接的生存周期
|
2013-08-18 17:42:25 +08:00
|
|
|
dp->set_idle(1);
|
|
|
|
for (int i = 0; i < 10; i++)
|
|
|
|
{
|
2015-09-08 17:21:04 +08:00
|
|
|
db_handle* dh = (db_handle*) dp->peek();
|
2013-08-18 17:42:25 +08:00
|
|
|
dbs.push_back(dh);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::list<db_handle*>::iterator it = dbs.begin();
|
|
|
|
for (; it != dbs.end(); ++it)
|
|
|
|
{
|
|
|
|
dp->put(*it);
|
|
|
|
//sleep(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
dbs.clear();
|
|
|
|
|
|
|
|
printf("dbpool count: %d\r\n", dp->get_dbcount());
|
|
|
|
sleep(2);
|
|
|
|
db_handle* dh = dp->peek();
|
|
|
|
dp->put(dh);
|
|
|
|
printf("dbpool count: %d\r\n", dp->get_dbcount());
|
|
|
|
delete dp;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|