Alice Alice - 4 months ago 18
Java Question

In my scheduleAtFixedRate method, I put delay time to start run the method. But this delay time cannot work and run immediatly

Here my code,

static ScheduledExecutorService scheduler = null;
scheduler.scheduleAtFixedRate(new Testing(),60, 24*60*60,TimeUnit.SECONDS);


public static Runnable Testing()
{ System.out.println("Testing...");
}


I want to call Runnable() method after 60 seconds later, but it call this method immediatly when i run the code.
Is there any problem in my code.
I'm new for scheduleAtFixedRate method.
Thanks :)

Answer

Please try this

scheduler.scheduleAtFixedRate(new Runnable() {
  @Override
  public void run() {
    System.out.println("Testing...");
  }
}, 60, 24*60*60,TimeUnit.SECONDS);