[英]Is there any thread limit on CompletableFuture.runAsync
I have a Rest api, in which it calls a async call like below我有一个 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);
}
});
when i call Rest api, it executed async call correctly.当我调用 Rest api 时,它正确执行了异步调用。 But i have a case where i called Rest Api, 4 times and it executed Async call for 3 and for the 4th Api call i dont see Async method being called.但是我有一个案例,我调用了 Rest Api,4 次,它执行了 3 次异步调用和第 4 次 Z72664DC0959F3B0C04891F8C7046A9FZ 调用异步调用,请参阅不调用异步调用方法。
Is there any limit on runAsync() call? runAsync() 调用有任何限制吗? or why is it not calling Async method after 3 calls?或者为什么在 3 次调用后不调用 Async 方法?
Here is the Rest API call:这是 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
}
What you have encountered is the number of threads configured in the ForkJoinPool.commonPool()
.您遇到的是ForkJoinPool.commonPool()
中配置的线程数。
The task assigned to runAsSync
is completed by the ForkJoinPool.commonPool()
.分配给runAsSync
的任务由ForkJoinPool.commonPool()
完成。 This pool is configured on the basis of the number of cores in your host computer.此池是根据主机中的内核数配置的。 It seems that you have 4 cores.看来你有4个核心。
By default, the size of the common pool:默认情况下,公共池的大小:
Runtime.getRuntime().availableProcessors() - 1
You can update the size:您可以更新大小:
-Djava.util.concurrent.ForkJoinPool.common.parallelism=8
Alternatively you can use the overloaded runAsSync with the executors argument.或者,您可以将重载的runAsSync与 executors 参数一起使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.