240717班级,工业化控制系统,煤矿相关行业,昆仑系统
Administrator
2024-11-06 731aab44a67db573ab7a9e6af8bfecf6efebbd23
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#pragma once
 
#include <queue>
#include <mutex>
#include <condition_variable>
//#include <json/json.h>
 
#include "MysqlConn.h"
 
//using namespace Json;
 
class ConnectionPool
{
public:
    static ConnectionPool* getInstance( );
 
    std::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();  // Ôö¼ÓÁ¬½ÓÊý
 
    std::string  m_ip;
    std::string  m_userName;
    std::string  m_passwd;
    std::string  m_db;
    unsigned short m_port;
 
    int m_max_conn;
    int m_min_conn;
 
    int m_timeout;      // Á¬½Ó³¬Ê±Ê±¼ä
    int max_del_time;   // ×î´óɾ³ýʱ¼ä( Á¬½Ó¿ÕÏÐʱ¼ä³¬¹ýÕâ¸ö,¾Í¸øµ±Ç°Á¬½Ó¹Ø±Õ )
    std::queue<MysqlConn*>m_connkQueue ;   // Á¬½Ó¶ÓÁÐ
    std::mutex m_mutex;  // »¥³âËø
    std::condition_variable m_cond;   // Ìõ¼þ±äÁ¿
};