通过模拟计时器让线程进入等待状态
代码如下:
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();
}
}
}
}