aditya soni
aditya soni

Reputation: 65

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:

  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.

Upvotes: 0

Views: 60

Answers (1)

Mick
Mick

Reputation: 973

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?

Upvotes: 1

Related Questions