Naming Thread and Current ThreadNaming ThreadThe Thread class provides methods to change and get the name of a thread. By default, each thread has a name i.e. thread-0, thread-1 and so on. By we can change the name of the thread by using setName() method. The syntax of setName() and getName() methods are given below:
Example of naming a threadOutput:Name of t1:Thread-0 Name of t2:Thread-1 id of t1:8 running... After changeling name of t1:Sonoo Jaiswal running... Current ThreadThe currentThread() method returns a reference of currently executing thread. Example of currentThread() methodOutput:Thread-0 Thread-1 Next TopicThread Priority
|