首页 > 其他 > 详细

Thread和Runnable

时间:2014-09-26 00:45:59      阅读:295      评论:0      收藏:0      [点我收藏+]

class TestThread extends Thread{
  public void run(){
    for(int i=0;i<10;i++){
      System.out.println(Thread.currentThread().getName()+"---is running");
    }
  }
}
public class Thread01 {
  public static void main(String[] args) {
    TestThread tt1 = new TestThread();
    TestThread tt2 = new TestThread();
    tt1.start();
    tt2.start();
    new Thread(new Runnable() {
          @Override
        public void run() {
          for(int i=0;i<20;i++){
            System.out.println(Thread.currentThread().getName()+"----is running");
          }
      }
    }).start();
  }
}

运行结果:

Thread-1---is running
Thread-2----is running
Thread-0---is running
Thread-2----is running
Thread-1---is running
Thread-2----is running
Thread-0---is running
Thread-2----is running
Thread-1---is running
Thread-2----is running
Thread-2----is running
Thread-0---is running
Thread-2----is running
Thread-1---is running
Thread-2----is running
Thread-0---is running
Thread-2----is running
Thread-1---is running
Thread-2----is running
Thread-0---is running
Thread-2----is running
Thread-1---is running
Thread-2----is running
Thread-0---is running
Thread-2----is running
Thread-1---is running
Thread-2----is running
Thread-0---is running
Thread-2----is running
Thread-1---is running
Thread-2----is running
Thread-0---is running
Thread-2----is running
Thread-1---is running
Thread-2----is running
Thread-0---is running
Thread-2----is running
Thread-1---is running
Thread-2----is running
Thread-0---is running

Thread和Runnable

原文:http://www.cnblogs.com/nathanieltian/p/3993899.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!