共計 252 個字符,預計需要花費 1 分鐘才能閱讀完成。
可以通過 Thread 類的 getName() 方法來獲取當前線程的名稱。
示例代碼如下:
public class Main {public static void main(String[] args) {Thread currentThread = Thread.currentThread();
String threadName = currentThread.getName();
System.out.println(" 當前線程名稱:" + threadName);
}
}
運行結果:
當前線程名稱:main
丸趣 TV 網 – 提供最優質的資源集合!
正文完