I am using Timer Thread to run a simple print function. The thing is that if I set my delay time is 1000ms, the program would just exit without any output.
But if I switch to 100ms, the program would be just fine.
public class TimerTaskTest01 {
public static void main(String[] args) {
Timer timer = new Timer();
timer.schedule(new MyTask(), 1000);
}
}
class MyTask extends TimerTask {
@Override
public void run() {
for (int i = 0; i < 10; i++) {
System.out.println("Hello World... ");
}
System.out.println("END");
}
}
I think maybe the main thread is running too fast. But is there anyone can tell me that if I am right or not...