1
zj
2024-11-12 cd95c9114fcbb3fc65c666b8b86c378f9a96d55b
bitgetsClient/src/main/java/org/example/bitgetsclient/WsBean/BitgetsWsBean.java
@@ -4,12 +4,15 @@
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;
@@ -19,6 +22,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
/**
@@ -39,7 +43,7 @@
    @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();
@@ -51,8 +55,11 @@
                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();
                });
            }
        }
    }