理解currentThread

示例:
public class MyThread extends Thread {

	public MyThread(String name) {
		super(name);
		System.out.println("ThreadName構造器");
		System.out.println("this.getName() ="+this.getName());
		System.out.println("Thread.currentThread().getName() ="+Thread.currentThread().getName());
	}

	@Override
	public void run() {
		System.out.println("ThreadName運行中");
		System.out.println("this.getName() ="+this.getName());
		System.out.println("Thread.currentThread().getName() ="+Thread.currentThread().getName());
	}
	
	public static void main(String[] args) {
		MyThread runthread = new MyThread("runthread");
		Thread reallyThread = new Thread(runthread,"reallyThread");
		reallyThread.start();
	}
}



結果:
ThreadName構造器
this.getName() =runthread
Thread.currentThread().getName() =main
ThreadName運行中
this.getName() =runthread
Thread.currentThread().getName() =reallyThread
java

相關文章
相關標籤/搜索