There is a method foo() in controller, which have to wait another method bar() triggered to continue execution.
@GetMapping("/foo")
public void foo(){
doSomething();
// wait until method bar() triggered
doAnotherSomething();
}
@GetMapping("/bar")
public void bar(){
// make foo() continue execute after being called
}
My solution is: saving a status flag in database/cache, while foo() is waiting, the thread loops searching if the status changed. However, this solution will blocke request thread for seconds. Is there any way to make foo() method run asynchronously, thus won't block thread execution?