#
Junjie
17 小时以前 c8de85433e5800a7b5595a96d99f4b49f24c38b4
src/main/java/com/zy/core/thread/impl/ZyStationThread.java
@@ -45,6 +45,9 @@
    private ZyStationConnectDriver zyStationConnectDriver;
    private int deviceLogCollectTime = 200;
    private long deviceDataLogTime = System.currentTimeMillis();
    private volatile boolean closed = false;
    private Thread mainThread;
    private Thread readThread;
    public ZyStationThread(DeviceConfig deviceConfig, RedisUtil redisUtil) {
        this.deviceConfig = deviceConfig;
@@ -56,13 +59,16 @@
    public void run() {
        this.connect();
        deviceLogCollectTime = Utils.getDeviceLogCollectTime();
        mainThread = Thread.currentThread();
        //设备读取
        Thread readThread = new Thread(() -> {
            while (!Thread.currentThread().isInterrupted()) {
        readThread = new Thread(() -> {
            while (!closed && !Thread.currentThread().isInterrupted()) {
                try {
                    readStatus();
                    Thread.sleep(200);
                } catch (InterruptedException ie) {
                    Thread.currentThread().interrupt();
                    break;
                } catch (Exception e) {
                    log.error("StationThread Fail", e);
                }
@@ -70,7 +76,7 @@
        });
        readThread.start();
        while (!Thread.currentThread().isInterrupted()) {
        while (!closed && !Thread.currentThread().isInterrupted()) {
            try {
                int step = 1;
                Task task = MessageQueue.poll(SlaveType.Devp, deviceConfig.getDeviceNo());
@@ -85,6 +91,9 @@
                        break;
                }
                Thread.sleep(200);
            } catch (InterruptedException ie) {
                Thread.currentThread().interrupt();
                break;
            } catch (Exception e) {
                e.printStackTrace();
            }
@@ -160,13 +169,25 @@
    @Override
    public boolean connect() {
        zyStationConnectDriver = new ZyStationConnectDriver(deviceConfig);
        new Thread(zyStationConnectDriver).start();
        zyStationConnectDriver.start();
        DeviceConnectPool.put(SlaveType.Devp, deviceConfig.getDeviceNo(), zyStationConnectDriver);
        return true;
    }
    @Override
    public void close() {
        closed = true;
        Thread t = mainThread;
        if (t != null) {
            try { t.interrupt(); } catch (Exception ignore) {}
        }
        Thread rt = readThread;
        if (rt != null) {
            try { rt.interrupt(); } catch (Exception ignore) {}
        }
        if (zyStationConnectDriver != null) {
            zyStationConnectDriver.close();
        }
    }
    @Override