【多线程实现方案一:继承Thread 类】
2021-07-13 16:05
标签:des ide pack for author color read com star 自定义类MyThread继承Thread类: 创建对象,给线程命名,启动线程: 【多线程实现方案一:继承Thread 类】 标签:des ide pack for author color read com star 原文地址:https://www.cnblogs.com/zuixinxian/p/9542634.htmlpackage com.shusheng.tihuzhai.test;
/**
* @author shusheng
* @description
* @Email shusheng@yiji.com
* @date 2018/8/27 14:54
*/
public class MyThread extends Thread {
public MyThread(){}
public MyThread(String name){
super(name);
}
@Override
public void run(){
for(int x=0;x){
System.out.println(getName()+":"+x);
}
}
}
package com.shusheng.tihuzhai.test;
/**
* @author shusheng
* @description
* @Email shusheng@yiji.com
* @date 2018/8/27 14:59
*/
public class TestMyThread {
public static void main(String[] args){
MyThread my1 = new MyThread("张三");
MyThread my2 = new MyThread("李四");
System.out.println(Thread.currentThread().getName());
my1.start();
my2.start();
}
}