线程中的sleep

package com.com.Prioity;

import java.text.SimpleDateFormat;
import java.util.Date;

public class MyThread extends Thread{

@Override
public void run() {
while (true){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date d = new Date();
System.out.println(sdf.format(d));
try {
Thread.sleep(1000);//睡一秒钟
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
MyThread mt= new MyThread();
mt.start();
}
}

posted @ 2022-05-17 17:12  小松2739  阅读(20)  评论(0编辑  收藏  举报