通过计时让线程进入等待状态

通过模拟计时器让线程进入等待状态
代码如下:

package com.thread;

/**
 * @author 邓亚非
 */
public class TimeWait implements Runnable{
    public static void main(String[] args) {
         TimeWait timeWait=new TimeWait();
         Thread thread=new Thread(timeWait);
         thread.start();
    }
    @Override
    public void run() {
        for (int i = 0; i <100 ; i++) {
            if (i%10==0){
                System.out.println(i);
            }
            System.out.println(i);
            try {
                Thread.sleep(1000);
                System.out.println("线程睡眠1秒!");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}


版权声明:本文为DYFNB原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。