| | |
| | | import org.apache.http.impl.client.DefaultHttpClient; |
| | | import org.apache.http.message.BasicNameValuePair; |
| | | import org.apache.http.util.EntityUtils; |
| | | import org.example.mexcclient.MexcClientApplication; |
| | | import org.example.mexcclient.pojo.Currency; |
| | | import org.example.mexcclient.server.impl.CurrencySerivceImpl; |
| | | import org.example.mexcclient.wsClient.MexcClient; |
| | |
| | | import org.json.JSONObject; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Qualifier; |
| | | import org.springframework.boot.SpringApplication; |
| | | import org.springframework.context.ConfigurableApplicationContext; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
| | |
| | | private CurrencySerivceImpl currencyService; |
| | | |
| | | @Autowired |
| | | private ConfigurableApplicationContext context; |
| | | |
| | | @Autowired |
| | | @Qualifier("threadPoolTaskExecutor") |
| | | private ThreadPoolTaskExecutor threadPoolTaskExecutor; |
| | | |
| | |
| | | List<Currency> sublist = mexc.subList(fromIndex, toIndex); |
| | | |
| | | // 使用自定义线程池提交任务 |
| | | threadPoolTaskExecutor.execute(new MexcClient(sublist)::start); |
| | | threadPoolTaskExecutor.execute(() -> { |
| | | try { |
| | | new MexcClient(sublist).start(); |
| | | } catch (Exception e) { |
| | | run(); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | 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(MexcClientApplication.class); |
| | | log.info("ws 重启成功"); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error("ws 重启失败"); |
| | | } |
| | | }); |
| | | restartThread.setDaemon(false); |
| | | restartThread.start(); |
| | | log.info("ws 重启失败"); |
| | | } |
| | | } |
| | | |