Reputation: 35
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
How I can validate values are inserted in DB by an Async method
call in my createUserRespone()
method.
How can we achieve it with Executor Framework or any other alternative will also appreciate ??
Please don't say make it a synchronous call
Upvotes: 0
Views: 1928
Reputation: 4243
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.
Upvotes: 1