1
zj
2025-07-15 e816946bb6e8f6b88045e565a3368c2367e7158a
kucoinClient/src/main/java/org/example/kucoinclient/WsBean/KucoinWsBean.java
@@ -39,15 +39,12 @@
    private CurrencySerivceImpl currencyService;
    @Autowired
    private ConfigurableApplicationContext context;
    @Autowired
    @Qualifier("threadPoolTaskExecutor")
    private ThreadPoolTaskExecutor threadPoolTaskExecutor;
    @Bean
    public void kucoinWebsocketRunClientMap() throws Exception {
        List<Currency> mexc = currencyService.list(new LambdaQueryWrapper<Currency>().eq(Currency::getSource, "kucoin"));
        List<Currency> mexc = currencyService.list(new LambdaQueryWrapper<Currency>().eq(Currency::getSource, "kucoin").eq(Currency::getQuoteAsset,"USDT"));
        if (!CollectionUtils.isEmpty(mexc)) {
            String result = doPost();
            JSONObject jsonObject = new JSONObject(result);
@@ -63,38 +60,11 @@
                // 使用自定义线程池提交任务
                threadPoolTaskExecutor.execute(() -> {
                    try {
                        new KucoinClient(sublist,token).start();
                    } catch (Exception e) {
                        run();
                    }
                    new KucoinClient(sublist,token).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(KucoinClientApplication.class);
                log.info("ws 重启成功");
            } catch (Exception e) {
                e.printStackTrace();
                log.error("ws 重启失败");
            }
        });
        restartThread.setDaemon(false);
        restartThread.start();
        log.info("ws 重启失败");
    }
    public static String doPost() throws Exception {