当我递归调用下面的方法时,它会被阻塞,不会抛出错误。没有回应。线程池大小为50。在处理10万条记录时,我面临这个问题。如何解决这个问题?提前谢谢
public void processActivityDeposits(
Activity activity) {
int partitionSize =
environment.getProperty("patition.size", Integer.class, 1000);
List<Long> records =
service.findReadyToProcessRecords(
activity.getActivityId(),
partitionSize);
if (records != null && records.size() > 0) {
try {
int threadPoolSize =
environment.getProperty("thread.pool.size", Integer.class, 10);
ExecutorService executorService = Executors.newFixedThreadPool(threadPoolSize);
for (Long activityId : records) {
executorService.execute(
new ActivityDepositInternalProcessor(
activityId));
}
executorService.shutdown();
try {
executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
e.printStackTrace();
}
processActivityDeposits(
activity);
} catch (Exception exception) {
exception.printStackTrace();
}
}
}
1条答案
按热度按时间ktca8awb1#
我建议您对代码进行以下更改。答。将执行服务创建和关闭移出if块。
b。不要将线程池大小设置为5以上,因为您只有一个核心,