package mythread;
public class Timer implements Runnable {
private Thread t; //定义一个线程
@Override
public void run() {
try {
for (int i = 10; i > 0; i--) {
System.out.println( i);
// 让线程睡眠一会
Thread.sleep(1000);//每隔1s执行一次循环
}
} catch (InterruptedException e) {
System.out.println("Thread interrupted.");
}
}
public static void main(String[] args) {
Timer timer = new Timer();
timer.run();
}
}