I am trying to stop a long running method after 10 seconds of execution, so far i followed the timer instructions on baeldung. https://www.baeldung.com/java-stop-execution-after-certain-time#1-using-a-timer When the method is a simple call to a thread sleep it works, but when I call my function with sub methods it doesn’t stop. My implementation looks like this: And the way I am calling
Tag: interrupt
Java long running task Thread interrupt vs cancel flag
I have a long running task, something like: The task can be cancelled (a cancel is requested and checkIfCancelRequested() checks the cancel flag). Generally when I write cancellable loops like this, I use a flag to indicate that a cancel has been requested. But, I know I could also use Thread.interrupt and check if the thread has been interrupted. I’m