1
zj
2024-08-07 ccb47a55a4ed9f3dbcaca9d40d8142515a91bdbe
geteClient/src/main/java/org/example/geteclient/WsBean/GateWsBean.java
@@ -30,9 +30,6 @@
    private CurrencySerivceImpl currencyService;
    @Autowired
    private ConfigurableApplicationContext context;
    @Autowired
    @Qualifier("threadPoolTaskExecutor")
    private ThreadPoolTaskExecutor threadPoolTaskExecutor;
@@ -51,38 +48,11 @@
                // 使用自定义线程池提交任务
                threadPoolTaskExecutor.execute(() -> {
                    try {
                        new GateClient(sublist).start();
                    } catch (Exception e) {
                        run();
                    }
                    new GateClient(sublist).start();
                });
            }
        }
    }
    private boolean runExecuted = false;
    private synchronized void run() {
        if (runExecuted) {
            return; // 已经执行过,直接返回
        }
        runExecuted = true;
        log.info("ws 异常开始重启");
        Thread restartThread = new Thread(() -> {
            try {
                SpringApplication.exit(context, () -> 0);
                SpringApplication.run(GeteClientApplication.class);
                log.info("ws 重启成功");
            } catch (Exception e) {
                e.printStackTrace();
                log.error("ws 重启失败");
            }
        });
        restartThread.setDaemon(false);
        restartThread.start();
        log.info("ws 重启失败");
    }
}