線程類的 getName() 方法用於返回線程的名稱。
用法
public final String getName()
返回
This method returns the name of thread.
示例
public class GetNameExample extends Thread
{
public void run()
{
System.out.println("Thread is running...");
}
public static void main(String args[])
{
// creating two threads
GetNameExample t1=new GetNameExample();
GetNameExample t2=new GetNameExample();
// return the name of threads
System.out.println("Name of t1:"+ t1.getName());
System.out.println("Name of t2:"+t2.getName());
// start t1 and t2 threads
t1.start();
t2.start();
}
}
輸出:
Name of t1:Thread-0 Name of t2:Thread-1 Thread is running... Thread is running...
相關用法
- Java Thread getContextClassLoader()用法及代碼示例
- Java Thread getThreadGroup()用法及代碼示例
- Java Thread getId()用法及代碼示例
- Java Thread getDefaultUncaughtExceptionHandler()用法及代碼示例
- Java Thread getState()用法及代碼示例
- Java Thread getStackTrace()用法及代碼示例
- Java Thread getPriority()用法及代碼示例
- Java Thread toString()用法及代碼示例
- Java Thread interrupted()用法及代碼示例
- Java Thread setDefaultUncaughtExceptionHandler()用法及代碼示例
- Java Thread suspend()用法及代碼示例
- Java Thread destroy()用法及代碼示例
- Java Thread holdLock()用法及代碼示例
- Java Thread setContextClassLoader()用法及代碼示例
- Java Thread sleep()用法及代碼示例
- Java Thread isInterrupted()用法及代碼示例
- Java Thread enumerate()用法及代碼示例
- Java Thread notify()用法及代碼示例
- Java Thread resume()用法及代碼示例
- Java Thread activeCount()用法及代碼示例
注:本文由純淨天空篩選整理自 Java Thread getName() method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。