Thread.CurrentThread.getName 与 this.getName()

public class CountOperate extends Thread {


public CountOperate() {

System.out.println("Thread.currentThread().getName():" + Thread.currentThread().getName());


               //this代表当前CountOperate对象,getName没有复写,所以调用Thread的getName方法,返回 "Thread-" + nextThreadNum()

System.out.println("this.getName():" + this.getName());
}

@Override

public void run(){

               //返回当前线程的name,t.setName("A");已经修改了线程名字

System.out.println("Thread.currentThread().getName():" + Thread.currentThread().getName())

               //this代表当前CountOperate对象,getName没有复写,所以调用Thread的getName方法,返回 "Thread-" + nextThreadNum()

System.out.println("this.getName():" + this.getName());
}



}


public class TestCurrentThread {


public static void main(String[] args) {
    
CountOperate c = new CountOperate();
Thread t = new Thread(c);
t.setName("A");
t.start();


}


}

你可能感兴趣的:(多线程)