多线程,获取当前线程的对象。

public class Demo02 {
public static void main(String[] args) {

Test01();
new Thread(){
public void run(){
System.out.println(getName()+".......ccccccccccc");
}
}.start();
new Thread( new Runnable(){
public void run(){
//Thread.currentThread()获取当前正在执行的线程
System.out.println(Thread.currentThread().getName()+"dddddddddd");
}
}).start();
System.out.println(Thread.currentThread().getName());//获取主线程的名字
Thread.currentThread().setName("我是主线程");
System.out.println(Thread.currentThread().getName());//再次获取主线程的名字

}
原文地址:https://www.cnblogs.com/wangffeng293/p/13347928.html