• Thread和Runnable


    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

  • 相关阅读:
    thinkphp 前台输出
    php的四种定界符
    面试总结
    Git分布式版本控制工具
    Apache Dubbo
    Mybatis03
    Mybatis02
    Mybaitis01
    linux下如何安装webbench
    SpringUtil
  • 原文地址:https://www.cnblogs.com/nathanieltian/p/3993899.html
Copyright © 2020-2023  润新知