线程休眠

package Chapter7.ShiLi.Demo6;

public class ThreadDemo {
  public static void main(String[] args) {
  System.out.println("Wait");
  Wait.bySec(5);
  System.out.println("start");
  }
}

 

package Chapter7.ShiLi.Demo6;

public class Wait {
  public static void bySec(long s){
  for (int i = 0; i < s; i++) {
  System.out.println(i+1+"秒");
  try {
    Thread.sleep(1000);//睡眠1秒
  } catch (InterruptedException e) {
    e.printStackTrace();
  }
 }

  }
}

posted @ 2018-02-19 20:57  医者心  阅读(133)  评论(0编辑  收藏  举报