标签:err 函数调用 setname 16px static public over 子线程 pre
public class MyThread extends Thread {
public MyThread(){
System.out.println("---MyThread begin---");
System.out.println("Thread.currentThread.getName()=" +Thread.currentThread().getName());
System.out.println("this.getName()=" + this.getName());
System.out.println(Thread.currentThread() == this);
System.out.println("---MyThread begin---");
}
@Override
public void run(){
System.out.println("---run begin---");
System.out.println("Thread.currentThread.getName()=" +Thread.currentThread().getName());
System.out.println("this.getName()=" +this.getName());
System.out.println(Thread.currentThread() == this);
System.out.println("---run end ---");
}
public static void main(String[] args) throws InterruptedException {
MyThread tt = new MyThread();
Thread t1 = new Thread(tt);
t1.setName("test");
t1.start();
}
}
---MyThread begin---
Thread.currentThread.getName()=main //实体是指现在正在发生的线程:main线程
this.getName()=Thread-0 //实例:当前实例是“死的线程”,默认赋值是:
Thread-0false // 实体并不是实例
---MyThread begin---
---run begin---
Thread.currentThread.getName()=test
//实体是指现在正在发生的线程:test线程this.getName()=Thread-0
//实例:当前实例是“死的线程”,默认赋值是:
Thread-0false //当前的实体是:
test 并不是,tt这个对象的死线程---run end ---
public Thread(Runnable target) {
init(null, target, "Thread-" + nextThreadNum(), 0);
}
public static void main(String[] args) throws InterruptedException {
MyThread tt = new MyThread();
tt.setName("test");
tt.start();
}
---MyThread begin---
Thread.currentThread.getName()=main
this.getName()=Thread-0
false
---MyThread begin---
---run begin---
Thread.currentThread.getName()=test
this.getName()=test
true
---run end ---
Thread.currentThread().getName() 和 this.getName()区别详解
标签:err 函数调用 setname 16px static public over 子线程 pre
原文地址:http://www.cnblogs.com/xujintao/p/7380269.html