How to remove a task from ScheduledExecutorService?
Simply cancel the future returned by scheduledAtFixedRate(): // Create the scheduler ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1); // Create the task to execute Runnable r = new Runnable() { @Override public void run() { System.out.println(“Hello”); } }; // Schedule the task such that it will be executed every second ScheduledFuture<?> scheduledFuture = scheduledExecutorService.scheduleAtFixedRate(r, 1L, 1L, TimeUnit.SECONDS); // … Read more