线程,thread

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

public class BoilThread extends Thread{
 @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 extends Thread{
 @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();
  }
 }
}

posted @ 2011-09-29 18:39  代码学习者coding  阅读(112)  评论(0编辑  收藏  举报