java怎么获取当前线程名称

lewis 2017-11-23 18次阅读

可以通过Thread类的getName()方法来获取当前线程的名称。

示例代码如下:

public class Main {
    public static void main(String[] args) {
        Thread currentThread = Thread.currentThread();
        String threadName = currentThread.getName();
        System.out.println("当前线程名称:" + threadName);
    }
}

运行结果:

当前线程名称:main


发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。