java中在构造方法中修改线程名,修改失败原因(现已修改成功)

2021-04-21 09:28

阅读:613

标签:span   hello   for   启动   col   reads   setname   ack   public   

package com.cx.Threads;

public class HelloThread extends Thread{


    @Override
    public void run() {
        for (int i = 0; i ) {
            if(i%2==0){
                System.out.println(Thread.currentThread().getName()+":"+i);
            }
        }
    }
    public HelloThread(){

    }
    public HelloThread(String name){
        super();
    }
}
 1 package com.cx.Threads;
 2 
 3 public class Text {
 4     public static void main(String [] args  ){
 5     HelloThread t1=new HelloThread("线程一");
 6 
 7     t1.start();
 8         HelloThread t2=new HelloThread();
 9         t2.setName("线程二");//必须在启动start之前
10         t2.start();
11     }
12 }

 经过检查发现是super();应该改成super(name);

 

java中在构造方法中修改线程名,修改失败原因(现已修改成功)

标签:span   hello   for   启动   col   reads   setname   ack   public   

原文地址:https://www.cnblogs.com/pengsulong/p/13281968.html


评论


亲,登录后才可以留言!