在我的 scheduleAtFixedRate 方法中,我设置了延迟时间来开始运行该方法.但是这个延迟时间不能立即生效 [英] In my scheduleAtFixedRate method, I put delay time to start run the method. But this delay time cannot work and run immediatly

查看:191
本文介绍了在我的 scheduleAtFixedRate 方法中,我设置了延迟时间来开始运行该方法.但是这个延迟时间不能立即生效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码,

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


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

我想在 60 秒后调用 Runnable() 方法,但它在我运行代码时立即调用此方法.我的代码有问题吗.我是 scheduleAtFixedRate 方法的新手.谢谢:)

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 :)

推荐答案

请试试这个

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

这篇关于在我的 scheduleAtFixedRate 方法中,我设置了延迟时间来开始运行该方法.但是这个延迟时间不能立即生效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆