1

I am trying to save a document from a spring controller asynchronously. Since it can often fail I want to I have the following method on a service ran asynchronously so I can repeat the call. The UI client doesn't need to wait for it to complete.

@Service
public class AsyncService {

    @Autowired
    DocumentClient documentClient;

    @Async
    public void save(Document document)  {

        int tryCount = 0;
        while (tryCount < RETRY_LIMIT) {
            try {
                tryCount++;
                documentClient.save(document);
                return;
            } catch (Exception e) {
                if (tryCount < RETRY_LIMIT) {
                    log.info("Retrying save document");              
                }
            }
        }
    }
}

When I set a breakpoint at line documentClient.save(document); it is blocking and the controller is waiting. But when I set a breakpoint at "return" the call is executed async and the controller returns while I'm still paused at the breakpoint. Any ideas why this happens? I thought the whole method save(Document document) would be non-blocking.

I'm using Springboot 1.5 and Intellij as a debugger/runtime.

Mario Codes
  • 689
  • 8
  • 15
marting
  • 165
  • 1
  • 8

1 Answers1

0

Intellij by default suspends all threads. It can be configured on the breakpoint to suspend only the current thread and that solves the issue. Thanks you @M.Deinum for the answer.

marting
  • 165
  • 1
  • 8