/**
*
* 可运行例子。。
* @author lxq
*
*/
public class MyThread extends Thread{
@Override
public void run() {
// TODO Auto-generated method stub
int time = 5;//结束时间.
while(time>0){
System.out.println("当前时间为:"+new Date().toLocaleString());
//等待1秒.
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
time = time-1;//减一秒
}
System.out.println("线程结束!");
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new MyThread().start();//启动线程
}
} |
|