[英]Is there any thread limit on CompletableFuture.runAsync
我有一個 Rest api,它在其中調用如下所示的異步調用
CompletableFuture.runAsync(() -> {
// method call or code to be async.
try {
logger.info("======Before Async method call======with studySchemaEventId: "+enrollmentStudySchemaEventId);
this.performSimulation(studyId, enrollmentStudySchemaEventId, cloneOfFile, simulationRunInfo, totalAccrual);
logger.info("======After Async method call======with studySchemaEventId: "+enrollmentStudySchemaEventId);
} catch (SimulationException e) {
logger.error("Error running Async call for performSimulation()", e);
}
});
當我調用 Rest api 時,它正確執行了異步調用。 但是我有一個案例,我調用了 Rest Api,4 次,它執行了 3 次異步調用和第 4 次 Z72664DC0959F3B0C04891F8C7046A9FZ 調用異步調用,請參閱不調用異步調用方法。
runAsync() 調用有任何限制嗎? 或者為什么在 3 次調用后不調用 Async 方法?
這是 Rest API 調用:
@POST
@Path("/trigger")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@ApiOperation(value = "Trigger Simulation", tags = "Study Event Simulation")
public Response triggerSimulation(
@FormDataParam("file") InputStream file,
@FormDataParam("file") FormDataContentDisposition fileDetail ,
@FormDataParam("simulationRunInfo") SimulationRunInfo simulationRunInfo
)
{
// some other logic
// Async code here
}
您遇到的是ForkJoinPool.commonPool()
中配置的線程數。
分配給runAsSync
的任務由ForkJoinPool.commonPool()
完成。 此池是根據主機中的內核數配置的。 看來你有4個核心。
默認情況下,公共池的大小:
Runtime.getRuntime().availableProcessors() - 1
您可以更新大小:
-Djava.util.concurrent.ForkJoinPool.common.parallelism=8
或者,您可以將重載的runAsSync與 executors 參數一起使用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.