14
I have been researching some places on the Internet but I did not find consistency in the definitions given on the subject of thread in Java.
What are the possible states of a thread and what are its definitions.
14
I have been researching some places on the Internet but I did not find consistency in the definitions given on the subject of thread in Java.
What are the possible states of a thread and what are its definitions.
10
If it is specific to Java it is easy to find out since the states are defined by an enumeration, then it has all in the documentation of Thread.State
.
start()
)RUNNING
)Lock
or some operation of IODEAD
)It won’t vary much from this, but other implementations can use another set of states.
Note that the inconsistencies found probably occur because people are talking about different things. I keep the documentation, it’s certainly not wrong. When you find incoherence always go to what is official.
If you are not talking about Java the states may vary. Each platform can have its own control, including different from the operating system. If you’re curious see states of threads possible in C#.
10
Image taken from Thread States and Life Cycle.
The states, according to the documentation sane:
NEW: When the thread
is created, but did not invoke the start()
in the reference.
RUNNABLE : When returning from any state, or when the start()
in the reference.
BLOCKED:
thread
is considered in the state BLOCKED when waiting for data.thread
is also considered BLOCKED when it is awaiting the Lock
from another thread.WAITING: One thread
who is waiting indefinitely for another thread to perform a given action is in this state.
TIMED_WAITING: One thread
that is waiting for another thread to perform an action for up to a specified waiting time is in this state.
TERMINATED: One thread
who left is in this state.
To know the states, in the Java
you can use the method Thread.getState
returning:
Besides, you can call it isAlive()
TRUE
means the thread is in the state Runnable or in the state Non-runnable.
References:
Browser other questions tagged thread competition
You are not signed in. Login or sign up in order to post.
After that already had answer becomes complicated to change the context of the question :/
– Renan Gomes
@Renan thanks for your attention anyway!
– Pena Pintada