| | |
| | | import com.fasterxml.jackson.core.JsonProcessingException; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.example.bitgetsclient.BitgetsClientApplication; |
| | | import org.example.bitgetsclient.pojo.Currency; |
| | | import org.example.bitgetsclient.server.impl.CurrencySerivceImpl; |
| | | import org.example.bitgetsclient.wsClient.BitgetClient; |
| | | import org.json.JSONException; |
| | | 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; |
| | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | |
| | | @Bean |
| | | public void bitgetWebsocketRunClientMap() throws JSONException, JsonProcessingException { |
| | | List<Currency> mexc = currencyService.list(new LambdaQueryWrapper<Currency>().eq(Currency::getSource, "bitget")); |
| | | List<Currency> mexc = currencyService.list(new LambdaQueryWrapper<Currency>().eq(Currency::getSource, "bitget").eq(Currency::getQuoteAsset,"USDT")); |
| | | if (!CollectionUtils.isEmpty(mexc)) { |
| | | int batchSize = 100; // 每个线程处理的数据量 |
| | | int totalSize = mexc.size(); |
| | |
| | | int toIndex = Math.min(fromIndex + batchSize, totalSize); // 计算结束索引 |
| | | List<Currency> sublist = mexc.subList(fromIndex, toIndex); // 切分子列表 |
| | | String parameter = getParameter(sublist); // 获取参数 |
| | | // 使用自定义线程池提交任务 |
| | | threadPoolTaskExecutor.execute(new BitgetClient(parameter)::start); // 提交到线程池执行 |
| | | threadPoolTaskExecutor.execute(() -> { |
| | | new BitgetClient(parameter).start(); |
| | | |
| | | }); |
| | | |
| | | } |
| | | } |
| | | } |