简体   繁体   English

在@async带注释的函数中发生多个请求时会发生什么?

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

相关问题 当@Transactional注释方法被多个实例并行命中时会发生什么? - What happens when a @Transactional annotated method is hit in parallel by multiple instances? 将Java类注释为@WebService时会发生什么? - What happens when a java class is annotated @WebService? 在JMS侦听器中发生异常时会发生什么 - What happens when an exception occurs in JMS listener 尝试使用Java捕获 - 发生异常时会发生什么? - Try catch in Java - what happens when an exception occurs? 当请求到Tomcat服务器时会发生什么? - What happens when request comes to Tomcat server? 当Oracle(TAF)发生故障转移时,java连接池会发生什么情况? - What happens to java Connection Pools, when fail-over occurs with Oracle (TAF)? 当集群中相应的节点发生故障时,对请求的处理 - What happens to a request, when the corresponding node fails in a cluster Tomcat:HTTP Multipart请求被中断时会发生什么? - Tomcat: what happens when a HTTP Multipart request gets interrupted? 当请求超时时,http servlet会发生什么? - What happens with http servlet when request times out? 当我们创建多个对象时,静态块会发生什么? - what happens to static block when we create multiple objects?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM