使用Java提供的线程创建方式,创建线程类。线程的任务是每隔一秒以“09:23:12”的形式向系统输出设备打印时间。
import java.time.LocalTime;
public class Test implements Runnable{
public static void main(String[] args) {
Test01 test01 = new Test01();
Thread thread = new Thread(test01);
thread.start();
}
@Override
public void run() {
while (true) {
//while(true)为死循环,会一直循环输出时间,可定义int i = 10调整输出数据数量。
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
LocalTime time = LocalTime.now().withNano(0);
System.out.println(time);
}
}
}