I, entitled
Write an application using Java multi-threading mechanism to achieve synchronization output time display.
Second, the source code
package com;
import java.util.Date;
public class ThreadTime extends Thread {
public void run(){//重写run方法
Date date;
while(true){
date=new Date();
System.out.println(date);//输出当前时间
try {
this.sleep(2000);//休眠2秒
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public static void main(String[] args) {
ThreadTime threadTime=new ThreadTime();
threadTime.start();//启动Thread线程
}
}
Third, the operating results