综合管理平台数据库数据模拟程序
Administrator
2021-03-25 3c531709c279453b02c4b087466d79fa3491ee74
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package main;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;
 
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.base.Com;
import com.config.AppConfig;
import com.mode.Device_Inf;
import com.sql.MysqlConnPool;
import com.thread.Manage_Simul_SQL;
import com.thread.Manage_Simul_Server;
 
public class main_Demo_Manage_Simul {
    /**************************************************************************/
    /**************************************************************************/
    /**************************************************************************/
    /**************************************************************************/
    /**************************************************************************/
    public final static boolean app_debug = false;
    
    public final static double m_VersionNum = 1.101;
    public final static String m_Version = "Welcome To Use main_Demo_Manage_Simul V" 
                                            + m_VersionNum ;
    /**************************************************************************/
    
    
    /**************************************************************************/
    public static final int MysqlServer_Port = 3360;
    
    private static AppConfig m_AppConfig;
    
    private static MysqlConnPool GB_MysqlConnPool;
    
    public static Logger logger = null;
    
    public static List<Device_Inf> devices;
    
    static{        
        System.setProperty("log4j.configurationFile", "log4j2_demo_manage_simul.xml");
    }
    
     /*********************************************************************************************/
    /*********************************************************************************************/
    public static void main(String[] args) {
        
        logger = LogManager.getLogger(main_Demo_Manage_Simul.class);
        String ver = m_Version;
        
        logger.warn("main_MonitorServer_Motor Server V"+ver+" Started At DateTime: " + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
        //´´½¨config.xmlÎļþ
        m_AppConfig = new AppConfig();
        
        logger.warn("SQLserver IP£º" + m_AppConfig.getMysqlServerIp() + ", port: "+MysqlServer_Port);
        //³õʼ»¯Á¬½Ó³ØÖеĸ÷ÖÖ²ÎÊýÐÅÏ¢
        GB_MysqlConnPool = new MysqlConnPool(m_AppConfig.getMysqlServerIp(), MysqlServer_Port, 
                                                100);
        
        checkingMySQLServerStart();                //¼ì²âÊý¾Ý¿â·þÎñÊÇ·ñÆô¶¯
        /*********************************************************************************/
        
        Manage_Simul_SQL.queryAllDevice(GB_MysqlConnPool,devices);
        
        Manage_Simul_Server server = new Manage_Simul_Server(GB_MysqlConnPool,devices);
        server.run();
        
        
        while(true) {
            try {                
                Thread.sleep(1000);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        /*********************************************************************************/
    }
    
    public static void checkingMySQLServerStart(){
        int MysqlServer_Port = 3360;
        logger.warn("IP£º"+m_AppConfig.getMysqlServerIp()+"port"+MysqlServer_Port);            
        //³õʼ»¯Á¬½Ó³ØÖеĸ÷ÖÖ²ÎÊýÐÅÏ¢        m_AppConfig.getMysqlServerIp()
        GB_MysqlConnPool = new MysqlConnPool(m_AppConfig.getMysqlServerIp(), MysqlServer_Port, 5);
        while(true){
            Connection conn = null;
            try {
                logger.warn(" ¿ªÊ¼¼ì²âÊý¾Ý¿âÁ¬½Ó "+Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
                conn =  GB_MysqlConnPool.getConn();
                if(conn != null){
                    logger.warn("¼ì²âÊý¾Ý¿âÁ¬½Ó³É¹¦ ");
                    break;
                }
            } catch (Exception e) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e1) {
                    e1.printStackTrace();
                }
                logger.warn(" MySQL_FBSDEV not Start ... ");
            } finally {
                if(conn != null) {
                    try {
                        conn.close();
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}