예제 #1
0
 /// <summary>
 /// 添加异常
 /// </summary>
 /// <param name="name"></param>
 /// <param name="pool"></param>
 public void Add(string name, PoolBase pool)
 {
     dicPool[name] = new HealthItem()
     {
         Pool = (HikariPool)pool, Count = 0
     };
 }
예제 #2
0
        /// <summary>
        /// 开始监测
        /// </summary>
        private void Start()
        {
            while (true)
            {
                Task.Factory.StartNew(() =>
                {
                    List <string> lst = new List <string>();
                    foreach (var kv in dicPool)
                    {
                        var con = kv.Value.Pool.GetConnection(ConnectTime);
                        if (con == null)
                        {
                            kv.Value.Count++;
                            kv.Value.Tick = DateTime.Now.Ticks;
                            if (kv.Value.Count > 10)
                            {
                                Logger.Singleton.WarnFormat("连接池异常,连接池名称:{0},连接池配置:{1}", kv.Key, kv.Value.Pool.ConnectStr);
                            }
                        }
                        else
                        {
                            kv.Value.Count--;
                            con.Dispose();
                            if (kv.Value.IsSucess)
                            {
                                lst.Add(kv.Key);
                            }
                        }
                    }
                    if (lst.Count > 0)
                    {
                        HealthItem item = null;
                        foreach (string k in lst)
                        {
                            dicPool.TryRemove(k, out item);
                        }
                    }
                });

                Thread.Sleep(waitTime);
            }
        }