acl/lib_acl_cpp/samples/dbpool/main.cpp

38 lines
704 B
C++
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "stdafx.h"
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;
// ç<C3A7>剧ç†ç»Œæ´ªæ£½æ<C2BD>©ç´å¸´é<C2B4>¨å­æ•“ç€æ¨ºæ‡†é<E280A0>ˆŸ
dp->set_idle(1);
for (int i = 0; i < 10; i++)
{
db_handle* dh = (db_handle*) dp->peek();
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;
}