请看下面的代码
public class Test {
public Test()
{
Timer timer = new Timer();
timer.schedule(new TimerTask(){
public void run()
{
System.out.println("Updated");
}
}, System.currentTimeMillis(),1000);
}
public static void main(String[]args)
{
new Test();
}
}
在这里,您可以看到它没有打印任何内容!也就是说,时间未定!这是为什么?我想安排任务在每一秒发生。请帮忙!
最佳答案
您告诉 Timer
在执行 TimerTask
之前等待(大约)1363531420 毫秒。算下来大约有 42 年。您应该使用Timer.schedule(yourTask, 0, 1000)
.
关于java - 时间表错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15461997/