java 线程方法 ---- sleep()

 

class MyThread implements Runnable{

    @Override
    public void run() {
        for (int i = 0; i < 5; i++){
            System.out.println(Thread.currentThread().getName() + ": " +i);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
public class Test {

    public static void main(String[] args) throws InterruptedException {
        new Thread(new MyThread()).start();
    }

}

 

posted @ 2018-10-28 00:28  huanggy  阅读(180)  评论(0编辑  收藏  举报