I have a process where two endpoints do the following actions in parallel:
- Endpoint A (thread A): performs some business logic and creates a new DB resource
- Endpoint B (thread B): receives a webhook before Thread A creates the new resource but it needs to check that new resource in order to perform some business logic on its own
My first guess was to use a wait() on Thread B and notify() on Thread A once the resource is created but I dont have a shared resource that I can use as a monitor in those threads, as the new resource that B uses for its business logic is not even created yet on Thread A
My second guess was to use a BlockingQueue with a SchedulerExecutor on the service that serves the request of Trhead B so they get enqueued and dispatched with some delay in a way Thread A has time enough to create the new resource
Is there a cleaner way to do this?
Thanks in advance