我正在尝试一些代码以实现预定任务,并提出了这些代码。
import java.util.*;
class Task extends TimerTask {
int count = 1;
// run is a abstract method that defines task performed at scheduled time.
public void run() {
System.out.println(count+" : Mahendra Singh");
count++;
}
}
class TaskScheduling {
public static void main(String[] args) {
Timer timer = new Timer();
// Schedule to run after every 3 second(3000 millisecond)
timer.schedule( new Task(), 3000);
}
}
我的输出:
1 : Mahendra Singh
我希望编译器以3 s的周期间隔打印一系列Mahendra Singh,但是尽管等待了大约15分钟,但我只得到一个输出...我该如何解决呢?