1
zj
2024-08-08 a9e9e1207ce417388b1d8f03df5833cea24939b7
bitgetsClient/src/main/java/org/example/bitgetsclient/WsBean/BitgetsWsBean.java
@@ -38,9 +38,6 @@
    private CurrencySerivceImpl currencyService;
    @Autowired
    private ConfigurableApplicationContext context;
    @Autowired
    @Qualifier("threadPoolTaskExecutor")
    private ThreadPoolTaskExecutor threadPoolTaskExecutor;
@@ -59,38 +56,12 @@
                List<Currency> sublist = mexc.subList(fromIndex, toIndex); // 切分子列表
                String parameter = getParameter(sublist); // 获取参数
                threadPoolTaskExecutor.execute(() -> {
                    try {
                        new BitgetClient(parameter).start();
                    } catch (Exception e) {
                        run();
                    }
                    new BitgetClient(parameter).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(BitgetsClientApplication.class);
                log.info("ws 重启成功");
            } catch (Exception e) {
                e.printStackTrace();
                log.error("ws 重启失败");
            }
        });
        restartThread.setDaemon(false);
        restartThread.start();
        log.info("ws 重启失败");
    }
    public String getParameter(List<Currency> list) throws JsonProcessingException, JSONException {