处理多线程问题
This commit is contained in:
parent
55504f5198
commit
804ceba007
@ -470,11 +470,14 @@ public class PopulationServiceImpl extends AbstractService implements IPopulatio
|
||||
List<PopulationInfoBaseDTO> populationInfoBaseDTOs = new ArrayList<>();
|
||||
int size = populationInfoIds.size();
|
||||
int numThreads = size / 2 + (size % 2 == 0 ? 0 : 1); // 计算需要的线程数
|
||||
numThreads = numThreads == 0 ? 1 : numThreads;
|
||||
|
||||
ExecutorService executorService = Executors.newFixedThreadPool(numThreads);
|
||||
List<Future<List<PopulationInfoBaseDTO>>> futures = new ArrayList<>();
|
||||
|
||||
// 将populationInfoIds分割成多个子列表,每个子列表由一个任务处理
|
||||
int chunkSize = (int) Math.ceil((double) populationInfoIds.size() / numThreads);
|
||||
chunkSize = chunkSize == 0? 1 : chunkSize;
|
||||
List<List<String>> chunks = Lists.partition(populationInfoIds, chunkSize);
|
||||
|
||||
for (List<String> chunk : chunks) {
|
||||
|
Loading…
Reference in New Issue
Block a user