The Thread class provides methods to change and get the name of a thread.
|
Example of naming a thread:
Output:Name of t1:Thread-0
Name of t2:Thread-1
id of t1:8
running...
After changeling name of t1:Sonoo Jaiswal
running...
The currentThread() method:
| The currentThread() method returns a reference to the currently executing thread object. |
Syntax of currentThread() method:
- public static Thread currentThread(): returns the reference of currently running thread.
Example of currentThread() method:
Output:Thread-0
Thread-1
No comments:
Post a Comment