您的位置:首页 > 其它

Thread.CurrentThread.getName 与 this.getName()

2016-11-15 10:45 471 查看
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();

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  多线程