I'm working on a legacy system where they have Thread.sleep
in the controller. The scenario here is, once the request is received it polls another service until the criteria are met. The problem here is request processing thread is blocked because of polling
I'm trying to replace it with DeferredResult
which avoids blocking and uses callback-based method. The polling will be in a separate thread and once completed setResult
will be called and response will be given to the user.
Does it actually make sense to use DeferredResult for polling with an interval? Is there any impact on performance on load?
This is code:
while (status.equals("RUNNING")) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
log.error("Error while polling for status setting Thread to sleep.", e);
}
status = requestStatus();
}
The one which I'm trying to improve is based on this example