When you are programming with threads, understanding the life cycle of thread is very valuable. While a thread is alive, it is in one of several states. By invoking start() method, it doesn?t mean that the thread has access to CPU and start executing straight away. Several factors determine how it will proceed.
Different states of a thread are :

Different states implementing Multiple-Threads are:

Methods that can be applied apply on a Thread:
Some Important Methods defined in java.lang.Thread are shown in the table:
| Method | Return Type | Description |
| currentThread( ) | Thread | Returns an object reference to the thread in which it is invoked. |
| getName( ) | String | Retrieve the name of the thread object or instance. |
| start( ) | void | Start the thread by calling its run method. |
| run( ) | void | This method is the entry point to execute thread, like the main method for applications. |
| sleep( ) | void | Suspends a thread for a specified amount of time (in milliseconds). |
| isAlive( ) | boolean | This method is used to determine the thread is running or not. |
| activeCount( ) | int | This method returns the number of active threads in a particular thread group and all its subgroups. |
| interrupt( ) | void | The method interrupt the threads on which it is invoked. |
| yield( ) | void | By invoking this method the current thread pause its execution temporarily and allow other threads to execute. |
| join( ) | void | This method and join(long millisec) Throws InterruptedException. These two methods are invoked on a thread. These are not returned until either the thread has completed or it is timed out respectively. |
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: Life Cycle of Threads View All Comments
Post your Comment