在不是Thread类的子类中,如何获取线程对象的名称呢?

我想要获取main方法所在的线程对象的名称,该怎么办呢?
  遇到这种情况,Thread类就提供了一个很好玩的方法:
    public static Thread currentThread() 返回当前正在执行的线程对象

package cn.itcast_03;

/*
 * 在不是Thread类的子类中,如何获取线程对象的名称呢?
 *         public static Thread currentThread() 返回当前正在执行的线程对象(静态方法)
 *             Thread.currentThread().getName()
 */
public class MyThreadDemo {
    public static void main(String[] args) {
        // 我要获取main方法所在的线程对象的名称,该怎么办呢?
        // 遇到这种情况,Thread类就提供了一个很好玩的静态方法:
        // public static Thread currentThread() 返回当前正在执行的线程对象
        System.out.println(Thread.currentThread().getName()); // main
    }
}
原文地址:https://www.cnblogs.com/chenmingjun/p/8719735.html