فهرست منبع

中控稳定版v1.1

1062167724@qq.com 6 سال پیش
والد
کامیت
e72c0b60d1

+ 5 - 16
parkMonitor/Database2/ConnectionPoolManager.cs

@@ -151,6 +151,7 @@ namespace parkMonitor.Database2
                 {
                     conn = GetConnection(bq,1000);
                     CheckConnection(conn, bq);
+                    ReleaseConnection(conn, bq);
                 }
             }
             if (bq.Count() < min)
@@ -165,19 +166,6 @@ namespace parkMonitor.Database2
         /// <param name="bq"></param>
         public static void ReleaseConnection(Connection conn, BlockingQueue bq)
         {
-            //Connection temp = null;
-            //for (int i = 0; i < bq.Count(); i++)
-            //{
-            //    temp = (Connection)bq.Dequeue();
-            //    if (temp != null && temp.mySqlConnection != null && temp.mySqlConnection.ServerThread <= conn.mySqlConnection.ServerThread-100)
-            //    {
-            //        return;
-            //    }
-            //    else
-            //    {
-            //        bq.Enqueue(temp);
-            //    }
-            //}
             bq.Enqueue(conn);
         }
         public static bool CheckConnection(Connection conn, BlockingQueue bq)
@@ -194,8 +182,6 @@ namespace parkMonitor.Database2
                     isUseful = true;
                     Console.WriteLine("连接测试正常");
                 }
-                //ReleaseConnection(conn, bq);
-                //Console.WriteLine("连接检测成功,重新入队");
             }
             catch (Exception ex)
             {
@@ -220,7 +206,10 @@ namespace parkMonitor.Database2
                 while (bq.Count() > 0)
                 {
                     Connection connection = (Connection)bq.Dequeue();
-                    connection.Close();
+                    if (connection != null)
+                    {
+                        connection.Close();
+                    }
                 }
             }
             Console.WriteLine("所有连接成功关闭!");

+ 8 - 2
parkMonitor/Database2/DatabaseConnPoolFactory.cs

@@ -101,7 +101,10 @@ namespace parkMonitor.Database2
         {
             try
             {
-                mySqlConnection.Close();
+                if (mySqlConnection != null)
+                {
+                    mySqlConnection.Close();
+                }
             }
             catch (Exception ex)
             {
@@ -112,7 +115,10 @@ namespace parkMonitor.Database2
         {
             try
             {
-                mySqlConnection.Dispose();
+                if (mySqlConnection != null)
+                {
+                    mySqlConnection.Dispose();
+                }
             }
             catch (Exception ex)
             {

+ 1 - 1
parkMonitor/bll/MainBll.cs

@@ -77,7 +77,7 @@ namespace parkMonitor.bll
             CmdServer.ins.listen(CmdType.MainWinClosed, () =>
             {
                 ConnectionPoolManager.CloseAll(EntityForCore.remoteBQ);
-                ConnectionPoolManager.CloseAll(EntityForCore.localBQ);
+                //ConnectionPoolManager.CloseAll(EntityForCore.localBQ);
                 coreThread.Stop();
                 monitorThread.Stop();
             });

+ 7 - 3
parkMonitor/server/CoreThread/CoreThreadTest2.cs

@@ -108,7 +108,8 @@ namespace parkMonitor.server.CoreThread
         /// </summary>
         public void BeginWorking()
         {
-            Timer checkRemoteTimer = new System.Threading.Timer(CheckRemotePool, null, 3600000, 3600000);
+            Timer checkRemoteTimer = new System.Threading.Timer(CheckRemotePool, null, 36000, 36000);
+            Timer killTimeoutConnection = new System.Threading.Timer(KillTimeoutConnection, null, 36000, 36000);
             //Timer checkLocalTimer = new System.Threading.Timer(CheckLocalPool, null, 10000, 300000);
             //Timer logTimer = new System.Threading.Timer(displayLog, null, 1000, 30000);
             Object lockObj = new object();
@@ -289,12 +290,15 @@ namespace parkMonitor.server.CoreThread
         }
         private void CheckRemotePool(object o)
         {
-            ConnectionPoolManager.CheckConnPooling(3, 10, ConnectionPoolManager.remoteConf, EntityForCore.remoteBQ);
-            DBOperation.KillTimeOutConnection(null, 3600, EntityForCore.remoteBQ);
+            ConnectionPoolManager.CheckConnPooling(3, 10, ConnectionPoolManager.remoteConf, EntityForCore.remoteBQ);            
         }
         private void CheckLocalPool(object o)
         {
             ConnectionPoolManager.CheckConnPooling(3, 10, ConnectionPoolManager.localConf, EntityForCore.localBQ);
         }
+        private void KillTimeoutConnection(object o)
+        {
+            DBOperation.KillTimeOutConnection(null, 3600, EntityForCore.remoteBQ);
+        }
     }
 }