diff --git a/src/main/java/com/ipsplm/ws/SimulationWebsocket.java b/src/main/java/com/ipsplm/ws/SimulationWebsocket.java index dd48eb5..50dfe00 100644 --- a/src/main/java/com/ipsplm/ws/SimulationWebsocket.java +++ b/src/main/java/com/ipsplm/ws/SimulationWebsocket.java @@ -5,10 +5,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import javax.websocket.OnClose; -import javax.websocket.OnMessage; -import javax.websocket.OnOpen; -import javax.websocket.Session; +import javax.websocket.*; import javax.websocket.server.ServerEndpoint; import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.Executors; @@ -49,21 +46,26 @@ public class SimulationWebsocket { //发送开始仿真的信息 String result = simulationService.getPlantData(message); if ("Simulation Started".equals(result)) { - isSimulationRunning = true; - log.info("【仿真开始】"); - scheduler.scheduleAtFixedRate(() -> { - if (isSimulationRunning) { - String data = simulationService.getPlantData("SimulationProgress"); - // 根据需要处理和发送获取到的数据 - log.info("【仿真数据】:" + data); - sendMessage(data); - if("1".equals(data) || "1.00".equals(data)){ - sendMessage("ending"); + if (!isSimulationRunning) { + isSimulationRunning = true; + log.info("【仿真开始】"); + scheduler.scheduleAtFixedRate(() -> { + try { + if (isSimulationRunning) { + String data = simulationService.getPlantData("SimulationProgress"); + // 根据需要处理和发送获取到的数据 + log.info("【仿真数据】:" + data); + sendMessage(data); + if ("1".equals(data) || "1.00".equals(data)) { + sendMessage("ending"); + isSimulationRunning = false; + } + } + } catch (Exception e) { isSimulationRunning = false; - scheduler.shutdown(); } - } - }, 0, 10, TimeUnit.SECONDS); + }, 0, 10, TimeUnit.SECONDS); + } } else { sendMessage("Simulation Start Failed"); } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index d92da30..b028a67 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -24,8 +24,4 @@ spring: plant: socket: ip: 127.0.0.1 - port: 30000 - -mybatis-plus: - configuration: - log-impl: org.apache.ibatis.logging.stdout.StdOutImpl \ No newline at end of file + port: 30000 \ No newline at end of file