zoukankan      html  css  js  c++  java
  • java线程实现的两个方式

     1 //方式一
     2 public class TestThread1 {
     3     public static void main(String args[]) {
     4         Runner1 r = new Runner1();
     5         r.start();
     6         
     7         for(int i=0; i<100; i++) {
     8             System.out.println("Main Thread:------" + i);
     9         }
    10     }
    11 }
    12 
    13 class Runner1 extends Thread {
    14     public void run() {
    15         for(int i=0; i<100; i++) {
    16             System.out.println("Thread:" + i);
    17         }
    18     }
    19 }
    20 
    21 //能使用接口就不用从Thread类继承
    22 //方式二
    23 public class TestThread1 {
    24     public static void main(String args[]) {
    25         Runner1 r = new Runner1();
    26         r.run();
    27         Thread t = new Thread(r);
    28         t.start();
    29         
    30         for(int i=0; i<50; i++) {
    31             System.out.println("Main Thread:------" + i);
    32         }
    33     }
    34 }
    35 
    36 class Runner1 implements Runnable {
    37     public void run() {
    38         for(int i=0; i<50; i++) {
    39             System.out.println("Thread: " + i);
    40         }
    41     }
    42 }
  • 相关阅读:
    23-10 条件查询
    22-9 聚合函数
    关系抽取snowball
    关系抽取bootstrap
    NER
    GPT
    因果卷积 空洞卷积
    XL-NET
    transoformer-XL
    transoformer
  • 原文地址:https://www.cnblogs.com/wblyuyang/p/2470104.html
Copyright © 2011-2022 走看看