[英]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.