0

I am trying to define an Async method using Spring that needs to be called at the end of a synchronous function, like below:

void syncFunction() {
      ...

   asyncFuntion();
}


@Async 
void asyncFunction() {
      ...
}

I need to add a delay of 10 seconds before the execution of asyncFunction begins and would like to avoid adding Thread.sleep(). I've also explored @Scheduled annotation, but it doesn't seem to work for a one-time scheduled task. What is the best way to achieve this using Spring? Thanks in advance.

Simran
  • 1
  • 1
  • Why do you need a delay? You can use `ScheduledThreadPoolExecutor` – 123 May 08 '20 at 17:09
  • The `asyncFunction` depends on the completion of tasks from a third-party service invoked in `syncFunction`, hence requires a certain delay. I am looking for something using Spring framework. – Simran May 08 '20 at 18:39
  • You won't find anything spring specific, since `ScheduledThreadPoolExecutor` already does what you want. – 123 May 08 '20 at 19:11

0 Answers0