简体   繁体   English

在Spring Boot中,我有一个异步调用,我必须等待下一个线程等待直到CRUD操作

[英]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 在我的项目中..我有一个方法createUserRespone() ,用于将响应发送给用户,在进行异步调用之前,它会执行一些数据库操作,并且在createUserRespone()方法中,我正在从数据库中获取值,并在获取时我要检查值是否在数据库中转储的数据

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. 我如何验证值是通过createUserRespone()方法中的Async方法调用插入数据库中的。

  2. How can we achieve it with Executor Framework or any other alternative will also appreciate ?? 我们如何使用Executor框架或任何其他替代方案来实现它,我们也会感激不尽?

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. 第一个方法必须返回Future ,或者必须返回用于执行任务的Thread (Wait by using Future.get or Thread.join ). (通过使用Future.getThread.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. 如果第一个方法不能返回任何句柄,则必须在数据库中进行一些轮询,然后循环等待直到发生预期的数据更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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