Java Multi-Threading Question:
Download Job Interview Questions and Answers PDF
What are the different states of a threads lifecycle?
Answer:
Following are the different states of threads:
1. New – A thread is called in New state until the start() method is called for the object of that thread. The thread is not alive in this state.
2. Runnable – The thread is called in Runnable state after the start() method is called for the object of that thread. The thread may enter into the Runnable state from Running state. The thread is called alive in this state.
3. Running – The thread is called in Running state when the thread scheduler take it from the Runnable thread’s pool.
4. Waiting/Blocked/Sleeping – In these states the thread is alive but it’s not in Runnable state. A running thread is called in these states after wait() or sleep() method is called that thread or when the thread is blocked while waiting for I/O resources.
5. Dead – After the execution of run() method is complete then the thread is called in dead state. Once a thread is dead then it cannot be start again.
1. New – A thread is called in New state until the start() method is called for the object of that thread. The thread is not alive in this state.
2. Runnable – The thread is called in Runnable state after the start() method is called for the object of that thread. The thread may enter into the Runnable state from Running state. The thread is called alive in this state.
3. Running – The thread is called in Running state when the thread scheduler take it from the Runnable thread’s pool.
4. Waiting/Blocked/Sleeping – In these states the thread is alive but it’s not in Runnable state. A running thread is called in these states after wait() or sleep() method is called that thread or when the thread is blocked while waiting for I/O resources.
5. Dead – After the execution of run() method is complete then the thread is called in dead state. Once a thread is dead then it cannot be start again.
Download Java Multi-Threading Interview Questions And Answers
PDF
Previous Question | Next Question |
Explain the method of Thread class with example? | What is difference between thread and process? |