| 3 | using namespace acl; |
| 4 | |
| 5 | int main(void) |
| 6 | { |
| 7 | db_pool *dp = new mysql_pool("127.0.0.1:3306", "test_db", "zsxxsz", |
| 8 | "111111"); |
| 9 | |
| 10 | std::list<db_handle*> dbs; |
| 11 | |
| 12 | // 设置空闲连接的生存周期 |
| 13 | dp->set_idle(1); |
| 14 | for (int i = 0; i < 10; i++) |
| 15 | { |
| 16 | db_handle* dh = (db_handle*) dp->peek(); |
| 17 | dbs.push_back(dh); |
| 18 | } |
| 19 | |
| 20 | std::list<db_handle*>::iterator it = dbs.begin(); |
| 21 | for (; it != dbs.end(); ++it) |
| 22 | { |
| 23 | dp->put(*it); |
| 24 | //sleep(1); |
| 25 | } |
| 26 | |
| 27 | dbs.clear(); |
| 28 | |
| 29 | printf("dbpool count: %d\r\n", dp->get_dbcount()); |
| 30 | sleep(2); |
| 31 | db_handle* dh = dp->peek(); |
| 32 | dp->put(dh); |
| 33 | printf("dbpool count: %d\r\n", dp->get_dbcount()); |
| 34 | delete dp; |
| 35 | |
| 36 | return 0; |
| 37 | } |