Thread is the independent path of execution of a thread in a program. The JVM provides an application to execute the multiple thread running concurrently in an application.
In this Tutorial we want to describe you a code that help you in understanding to get a thread name. For this we have a class name Get Thread Name, Inside the class we have -
1)A GetThreadName implements the Runnable interface, that provides you to execute the thread. An object of GetThreadName is Runnable object.
2)We pass the Runnable object as argument to the Thread constructor that is used to create an object of thread.
3)The Thread object has a Runnable object that
implements the run method.
4)Once the thread object is created ,start method is invoked.
5)The start( )return immediately once a thread has been spawned.
6)th.getName-This method returns you the information about the particular thread running in the code and the information about the specified thread is printed by System.out.println.
7) The thread ends when the run( ) method ends.
On execution the code display you the list of thread executing in a program.
GetThreadName.java
|
Thread name : 1st Thread
|
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Get Thread Name View All Comments
Post your Comment