Actually, Spring @Async uses its own thread pool. And as long as the cancel () method of the Future or shutdownNow () function of the executing service, Calling executor.shutdownNow() or future.cancel(true) does not stop the current thread immediately. What these methods do is simply call .interrupt() on the appropriate thread (s). And interrupts has no guaranteed immediate effect . It issues a flag, so whenever it is in the idle or idle state, the thread stops.
It should be noted that if your tasks ignore interruption, executor.shutdownNow() and future.cancel(true) will behave exactly like executor.shutdown() and future.cancel(false) .
If you need a way to stop a slow or blocking operation. If you have a long / infinite loop, you can simply add the condition: Thread.currentThread().isInterrupted() and not continue if it is true (completion of the operation).
source share