zoukankan      html  css  js  c++  java
  • java, thread, runnable

    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();
      }
     }
    }

  • 相关阅读:
    hdu 2222 Keywords Search
    Meet and Greet
    hdu 4673
    hdu 4768
    hdu 4747 Mex
    uva 1513 Movie collection
    uva 12299 RMQ with Shifts
    uva 11732 strcmp() Anyone?
    uva 1401
    hdu 1251 统计难题
  • 原文地址:https://www.cnblogs.com/gujianhan/p/2195820.html
Copyright © 2011-2022 走看看