[英]What happens when multiple request occurs in a @async annotated function?
if already a request is processing and a new request occurred at same time into a @async annotated function lets say: 如果已经在处理请求,并且同时在@async带注释的函数中发生了新请求,则可以说:
public String importData(ImportRequest requestBody)
{
File file = new File(path.toString() + "/" +
requestBody.getFileName() + ".xlsx");
FileInputStream fis = new FileInputStream(file);
XSSFWorkbook workbook = new XSSFWorkbook(fis);
//Iterate through each rows one by one
Iterator<Row> rowIterator = sheet.iterator();
while (rowIterator.hasNext()) {
saveDataFromFileToDb();
}
}
if a file has 1000 rows and its still processing in background, and suddenly one more request arrives then what happens. 如果一个文件有1000行并且仍在后台处理,突然又有一个请求到达,那么会发生什么。
It will kick off another thread trying to do the same. 它将启动另一个尝试执行此操作的线程。 But you could configure a single-thread executor. 但是您可以配置单线程执行程序。 Your task will still be executed twice, but not in parallel. 您的任务仍将执行两次,但不会并行执行。
You are talking about Spring's @Async annotation, right? 您在谈论Spring的@Async注释,对不对?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.