zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    [Leetcode] Convert Sorted List to Binary Search Tree
    [Leetcode] Sqrt(x)
    [Leetcode] Pow(x, n)
    [Leetcode] Balanced Binary Tree
    [Leetcode] Convert Sorted Array to Binary Search Tree
    [Leetcode] Construct Binary Tree from Preorder and Inorder Traversal
    [Leetcode] Remove Element
    [Leetcode] Letter Combinations of a Phone Number
    [Leetcode] Generate Parentheses
    [Leetcode] Valid Parentheses
  • 原文地址:https://www.cnblogs.com/nathanieltian/p/3993899.html
Copyright © 2011-2022 走看看