java怎么获取当前线程名称

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

示例代码如下:

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

运行结果:

当前线程名称:main
阅读剩余
THE END