How to stop a task in ScheduledThreadPoolExecutor once I think it's completed
I have a ScheduledThreadPoolExecutor with which I schedule a task to run at a fixed rate. I want the task to be running with a specified delay for a maximum of say 10 times until it "succeeds". After that, I will not want the task to be retried. So basically I'll need to stop running the scheduled task when I want it to be stopped, but without shutting down the ScheduledThreadPoolExecutor. Any idea how I'd do that? Here's some pseudocode - public class ScheduledThreadPoolExecutorTest { public static ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(15); // no multiple