I have to build a service using Java and SpringBoot which will be responsible for polling an application via API till the conditions are met. So I'm sending POST request and the app has to do something. Then I'm sending GET request towards this app and fetching the data. I'm checking if the task is done. If not, I need to send this GET request one more time eg. every 10 seconds. If analysis is done, then I should stop polling. I've tried to use schedulers but there is a problem with checking conditions. Runnable object cannot return any value so I can't cancel the task in a proper moment. The second thing is that I can have more than one task at the same time to polling. Do you have any idea how I can resolve my problem?
I'm thinking at two options: