#pragma once
|
|
#include "MysqlConn.h"
|
|
class ConnectionPool
|
{
|
public:
|
static ConnectionPool* getInstance();
|
|
shared_ptr<MysqlConn> getMysqlConn(); // ´ÓÊý¾Ý¿âÁ¬½Ó³Ø»ñÈ¡Á¬½Ó
|
|
ConnectionPool(const ConnectionPool& other) = delete;
|
ConnectionPool& operator=(const ConnectionPool& other) = delete;
|
|
~ConnectionPool();
|
|
void description();
|
|
protected:
|
ConnectionPool(); // ¹¹Ô캯Êý
|
private:
|
// ²»ÔÙÐèÒª½âÎöÅäÖÃÎļþµÄº¯Êý
|
// bool parseJsonFile(); // ½âÎöÅäÖÃ
|
|
void produce();
|
void recycle();
|
void addConnection(); // Ôö¼ÓÁ¬½ÓÊý
|
|
// дËÀµÄÊý¾Ý¿âÁ¬½Ó²ÎÊý
|
string m_ip = "127.0.0.1";
|
string m_userName = "root";
|
string m_passwd = "123456";
|
string m_db = "mayi_kunlun";
|
unsigned short m_port = 3306;
|
|
int m_max_conn;
|
int m_min_conn;
|
|
int m_timeout; // Á¬½Ó³¬Ê±Ê±¼ä
|
int max_del_time; // ×î´óɾ³ýʱ¼ä( Á¬½Ó¿ÕÏÐʱ¼ä³¬¹ýÕâ¸ö,¾Í¸øµ±Ç°Á¬½Ó¹Ø±Õ )
|
queue<MysqlConn*> m_connkQueue; // Á¬½Ó¶ÓÁÐ
|
mutex m_mutex; // »¥³âËø
|
condition_variable m_cond; // Ìõ¼þ±äÁ¿
|
};
|