BUT2/DEV/DEV3.2/TP05_Files/Test.java

29 lines
681 B
Java
Raw Normal View History

2023-11-20 13:22:30 +01:00
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
public class Test extends TimerTask {
@Override
public void run() {
System.out.println("hello");
}
public static void main(String args[]){
Test timerTask = new Test();
//running timer task as daemon thread
Timer timer = new Timer(true);
timer.scheduleAtFixedRate(timerTask, 0, 1000);
try {
while(true){
Thread.sleep(1000);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
timer.cancel();
System.out.println("TimerTask cancelled");
}
}