*
lsh
9 天以前 7a0381baabd865d8339b02af822f1c4ffe6bf1bc
src/main/java/com/zy/core/thread/JarThread.java
@@ -40,6 +40,8 @@
    private JarSlave slave;
    private JarProtocol jarProtocol;
    private short heartBeatVal = 1;
    private boolean connectJar = false;
    public JarThread(JarSlave slave) {
        this.slave = slave;
@@ -48,7 +50,33 @@
    @Override
    @SuppressWarnings("InfiniteLoopStatement")
    public void run() {
        this.connect();
        connectJar = this.connect();
        while(!connectJar){
            try {
                connectJar = this.connect();
                Thread.sleep(100);
            } catch (Exception e){
            }
        }
        // 启动线程自动重连
        new Thread(this::jarConnect).start();
        // 启动读数据线程
        new Thread(this::readStatusJar).start();
        // 启动任务下发线程
        new Thread(this::taskIssued).start();
    }
    /**
     * 任务下发
     */
    private void taskIssued() {
        while (true) {
            try {
                int step = 1;
@@ -59,7 +87,7 @@
                switch (step) {
                    // 读数据
                    case 1:
                        readStatus();
//                        readStatus();
                        break;
                    // 写数据 ID+目标站
                    case 2:
@@ -70,14 +98,55 @@
                }
                // 心跳
//                heartbeat();
                Thread.sleep(500);
                Thread.sleep(200);
            } catch (Exception e) {
                e.printStackTrace();
                log.error("JAR写线程异常"+e.getMessage());
//                e.printStackTrace();
            }
        }
    }
    private void jarConnect() {
        while (true) {
            try {
                Thread.sleep(1000);
                if(!connectJar){
                    try {
                        connectJar = this.connect();
                        Thread.sleep(100);
                    } catch (Exception e){
                    }
                }
            } catch (Exception e) {
                log.error("rgv连接失败!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
                initSte();
//                e.printStackTrace();
            }
        }
    }
    private void readStatusJar() {
        while (true) {
            try {
                Thread.sleep(50);
//                System.out.println("读线程"+ slave.getId());
                readStatus();
            } catch (Exception e) {
                log.error("RGV数据读取线程异常!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
                initSte();
//                e.printStackTrace();
            }
        }
    }
    /**
     * 初始化堆垛机状态
     */