简体   繁体   中英

In Spring Boot i have a Async call and I have to wait my next thread to wait till CRUD Operation

In my project .. I have an method createUserRespone() which is used to send the response to user and before the there is an Async call which do some database operation and in createUserRespone() method I am fetching the value from DB and while fetching the data I want to check if the values are dump in DB or not

Example:

// here importScore is AN Async method
irResponse = scoreManager.importScore(fileUpload, loggedInUser);

CreateUserResponse response= this.createUserRespone( a, b);


private CreateUserResponse  createUserRespone(String a, Object b){

    // here I am fetching those values which are inserted from Async method call

}

My question

  1. How I can validate values are inserted in DB by an Async method call in my createUserRespone() method.

  2. How can we achieve it with Executor Framework or any other alternative will also appreciate ??

Please don't say make it a synchronous call

You need some handle on which you can wait. Either the first method has to return a Future , or it has to return a Thread which it is using to execute the task. (Wait by using Future.get or Thread.join ).

If the first method cannot return any handle, you have to do some polling in the DB and wait in a loop until the expected change in data has occurred.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM