zoukankan      html  css  js  c++  java
  • 继承类的线程写法

    package charpter1;

    //类继承父类
    public class MyThread01 extends Thread {
    // 重写父类方法
    @Override
    public void run() {
    // 让当前线程执行的代码编写在run方法中
    for (int i = 0; i <= 100; i++) {
    System.out.println("you: " + i);
    }
    }

    }

    -------------------------------

    package charpter1;

    public class TestThread02 {
    public static void main(String[] args) {
    new Thread(){

    @Override
    public void run() {
    for(int i=0;i<=100;i++){
    System.out.println("@@@@@@@@");
    }
    }

    }.start();
    System.out.println("main");
    new Thread(){

    @Override
    public void run() {
    for(int i=0;i<=100;i++){
    System.out.println("******");
    }
    }

    }.start();
    }
    }

    -----------------------------------------------

    package charpter1;

    public class TestThread01 {
    // main是一个线程
    public static void main(String[] args) {
    // 创建线程对象
    MyThread01 thread01 = new MyThread01();
    // 调用start方法只是告诉cpu当前线程准备就绪可以执行了,但是什么时候执行由cpu来决定
    thread01.start();// 启动线程的正确方式调用start方法
    // 创建线程对象
    MyThread02 MyThread02 = new MyThread02();
    MyThread02.start();
    System.out.println("main方法执行结束");

    }
    }

  • 相关阅读:
    objcopy使用
    linux中的strip命令简介
    strace命令详解
    bash执行顺序:alias --> function --> builtin --> program
    Ubuntu下安装docker
    uvm中类继承和phase
    error和exception有什么区别?
    sleep() 和 wait() 有什么区别?
    CSS3实现环形进度条?
    请写出你最常见到的5个runtime exception?
  • 原文地址:https://www.cnblogs.com/Koma-vv/p/9600212.html
Copyright © 2011-2022 走看看