62,614
社区成员
发帖
与我相关
我的任务
分享
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Timer myTimer = new Timer();
MyTimerTask myTask = new MyTimerTask();
myTimer.schedule(myTask,5000); // 五秒之后运行run方法,但是却没有运行,为什么啊?
try {
Thread.sleep(5000);
} catch (InterruptedException exc) {
}
myTimer.cancel();
}
}
import java.util.*;
public class MyTimerTask extends TimerTask {
public void run() {
System.out.println("Timer task executed.");
}
}
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Timer myTimer = new Timer();
MyTimerTask myTask = new MyTimerTask();
myTimer.schedule(myTask,5000); // 五秒之后运行run方法,但是却没有运行,为什么啊?
try {
Thread.sleep(6000);
} catch (InterruptedException exc) {
}
myTimer.cancel();
}
}