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