What are different thread states in Java
Carvia Tech | July 05, 2019 | 2 min read | 23 views
A thread in JVM can have 6 different states as defined in Thread.State enum. At any given time, thread must be in any of these states.
This state is for a thread which has not yet started.
This state is for the currently running thread which is executing in java virtual machine, but it may be waiting for the other resources from operating system such as processor.
Thread state for a thread blocked waiting for a monitor lock. A thread in this state can be waiting for a monitor lock to enter a synchronized block/method or reenter a synchronized method after calling
A thread is waiting due to calling on one of the method -
Object.wait with no timeout
Thread.join with no timeout
A Thread in this state is waiting for another thread to perform a particular action. For example, a thread that has called
Object.wait() on an object is waiting for another thread to call
Object.notifyAll() on that object. A thread that has called
Thread.join() is waiting for a specified thread to terminate.
Thread state for a waiting thread with a specified waiting time. A thread is in the timed waiting state due to calling one of the following methods with a specified positive waiting time -
Object.wait with timeout
Thread.join with timeout
Thread state for a terminated thread. The thread has completed execution.
This content has been taken directly from the Java Docs - Thread.State enum.
Top articles in this category:
- Top 50 Multi-threading Java Interview Questions for Investment Bank
- Citibank Java developer interview questions
- Java Concurrency Interview Questions and Answers
- Morgan Stanley Investment Banking Java Interview Questions
- RBS Java Programming Interview Questions
- BlackRock Top Java Interview Questions: Investment Banking Domain
- Goldman Sachs Java Interview Questions for Senior Developer
Find more on this topic:
Interview - Product Companies, eCommerce Companies, Investment Banking, Healthcare Industry, Service Companies and Startups.
Last updated 1 week ago
Recommended books for interview preparation:
- Send GMAIL emails from Java and Spring
- Send Mandrill emails from Spring Boot in Java
- Top 30 Hibernate and Spring Data JPA interview questions
- Generating variable length secure key/secret in Java
- Reverse the bits of a number and check if the number is palindrome or not
- MD5 and SHA-256 in Java Kotlin and Android
- Spring Security 5 - There is no PasswordEncoder mapped for the id
- Inter-thread communication in Java
- What are different thread states in Java
- Static method synchronization aka Class Lock in Java
Enter your email address to subscribe to this blog and receive notifications of new posts by email.