public class Main {
  public static void main(String[] args) {
   new Thread(new BoilThread()).start();
   new Thread(new WashThread()).start();
  }
}

 

public class BoilThread implements Runnable{
 @Override
 public void run() {
  // TODO Auto-generated method stub
  try {
   System.out.println("开始烧水。。。");
   Thread.sleep(10000);
   System.out.println("水烧开了。。。");
  } catch (Exception e) {
   // TODO: handle exception
   e.printStackTrace();
  }
 }
}

 

public class WashThread implements Runnable{
 @Override
 public void run() {
  try {
   for(int i=0;i<5;i++){
   System.out.println("开始洗茶杯。。。");
   Thread.sleep(200);
   System.out.println("第"+(i+1)+"个茶杯洗干净了。。。");
   }
  } catch (Exception e) {
   // TODO: handle exception
   e.printStackTrace();
  }
 }
}

相关文章:

  • 2018-10-25
  • 2021-12-03
  • 2022-02-02
  • 2021-10-25
  • 2022-02-09
  • 2021-06-30
  • 2021-06-26
  • 2022-03-03
猜你喜欢
  • 2021-10-17
  • 2022-12-23
  • 2022-02-08
  • 2021-10-29
  • 2022-02-06
  • 2022-12-23
相关资源
相似解决方案