共計 376 個字符,預計需要花費 1 分鐘才能閱讀完成。
在 Java 中,可以通過 Thread 類的 getName() 方法來獲取線程的名稱。例如:
Thread t = new Thread();
String threadName = t.getName();
System.out.println("Thread name: " + threadName);
另外,可以使用 Thread.currentThread() 方法來獲取當前執行線程的引用,然后調用 getName() 方法來獲取當前線程的名稱,例如:
Thread currentThread = Thread.currentThread();
String currentThreadName = currentThread.getName();
System.out.println("Current thread name: " + currentThreadName);
丸趣 TV 網 – 提供最優質的資源集合!
正文完