【发布时间】:2021-06-25 21:29:08
【问题描述】:
我有一个 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 时,它正确执行了异步调用。 但是我有一个案例,我调用了 4 次 Rest Api,它执行了 3 次异步调用,而对于第 4 次 Api 调用,我没有看到调用了 Async 方法。
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
}
【问题讨论】:
-
这4个电话你是怎么写的?可以附上代码吗?
-
更新代码@polypiel
标签: java multithreading asynchronous threadpool completable-future