该方法返回代码正在被那个线程调用的信息
package mythread;
public class CountOperate extends Thread {
public CountOperate() {
System.out.println("CountOperate --- begin");
System.out.println("Thread.currentThread().getName()=" + Thread.currentThread().getName());
System.out.println("this.getName()=" + this.getName());
System.out.println("CountOperate --- end");
}
public CountOperate(String name) {
this.setName(name);
System.out.println("CountOperate --- begin");
System.out.println("Thread.currentThread().getName()=" + Thread.currentThread().getName());
System.out.println("this.getName()=" + this.getName());
System.out.println("CountOperate --- end");
}
@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("run end");
}
}
package mythread;
public class test {
public static void main(String[] args) {
CountOperate c = new CountOperate("B");
// c.start();
Thread t1 = new Thread(c,"S");
t1.setName("A");
t1.start();
}
}
CountOperate --- begin
Thread.currentThread().getName()=main
this.getName()=B
CountOperate --- end
run begin
Thread.currentThread().getName()=A
this.getName()=B
run end