I have a method which works for several minutes and I get time-out error. I have optimized code, but anyway, request is too large. That`s why I came to this: I call service layer at a new thread and return immediatly 200 Ok status to browser.
Then after service layer work is finished, I want to send to browser success status using WebSocket. It will generate notification and client will be notified about it.
public myMethod(){
new Thread(()-> {
try {
commonImportService.load(docId, documentType);
} catch (IOException | WorkflowException | IntegrationException e) {
e.printStackTrace();
}}).start();
return new ResponseEntity<>(HttpStatus.OK);
}
But I get next error
Error creating bean with name 'scopedTarget.userUtils': Scope 'request' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton;
I assume my service layer needs access to request, to get information about customer and so on from token, but as I returned 200 Ok, request is closed.
How should I solve this problem properly?