java tutorial - Naming Thread and Current Thread - java programming - learn java - java basics - java for beginners
Learn Java - Java tutorial - Naming a thread - Java examples - Java programs
Naming Thread
- Thread class provides methods to alter then it get the name of the thread.
- By default, each thread have a name i.e. thread-0, thread-1 and so on.
- We can change the name of the thread by using the setName() method.
Syntax
Method | Description |
---|---|
public String getName() | Used to return the name of a thread. |
public void setName(String name) | Used to change the name of a thread. |
Sample Code
Current Thread
- The currentThread() method returns a reference of presently executing thread.