0

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?

John Hue
  • 25
  • 1
  • 4
  • Where is you service component definition? Could you add the right code and not a pseudo-illustration of it. – tmarwen Oct 15 '21 at 10:02
  • Does this answer your question? [How to enable request scope in async task executor](https://stackoverflow.com/questions/23732089/how-to-enable-request-scope-in-async-task-executor) – Darren Forsythe Oct 15 '21 at 11:05

0 Answers0