-2

I use ScheduledExecutorService to do a timer task:

scheduledExcutorService.schedule(timerTask, 5000, TimeUnit.MILLISECONDS)

The TimerTask is a Runnable object:

public class TimerTask implements Runnable {
    public void run() {
        //do something
    }
}

Usually, I want to do something in 5 minutes, but in some conditions, I need to delay this task.(cancel it and put it to the ScheduledExecutorService again with another 5 minutes delay)
But how can I achieve this?

zaihui
  • 53
  • 1
  • 9
  • I am pointing to another thread which has an answer to your query: https://stackoverflow.com/questions/32001/resettable-java-timer – akshaya pandey Nov 10 '17 at 06:55
  • Actually I know how to do this with Timer and TimerTask, but I prefer doing this by ScheduledExecutorService – zaihui Nov 11 '17 at 14:59

1 Answers1

-1

Thread.currentThread().sleep(1000);//Millisecond

hzd
  • 1