multithreading – The difference between BLOCKED and TIMED_WAITING on java
You’re right, the thread state for a Thread
inside the method Thread.sleep
should be TIMED_WAITING
.
multithreading – The difference between BLOCKED and TIMED_WAITING on java
To cite the authoritative source:
public static final Thread.State TIMED_WAITING
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:
Thread.sleep
Object.wait
with timeout
Thread.join
with timeout
LockSupport.parkNanos
LockSupport.parkUntil
I tested several Java versions (Oracle’s implementation) in the range 1.6
to 1.8
, inclusive, and all show the correct behavior of reporting threads inside Thread.sleep
with the state TIMED_WAITING
.
It’s also important to consider the following statement about Thread.sleep()
:
… The thread does not lose ownership of any monitors.
So, since the thread does not lose ownership of monitors, it won’t reacquire monitors. So it shouldn’t be in Thread.State.BLOCKED
.
So either you are using a different JVM/JRE implementation or a modified Thread
class, maybe it has been modified via Instrumentation at runtime. In either case, the information you have given in your question are not enough to narrow your problem further.
It would be useful as well to know which version of jstack
you have used as the output has a different format than I got. Maybe it’s the tool which prints the state wrong…
multithreading – The difference between BLOCKED and TIMED_WAITING on java
multithreading – The difference between BLOCKED and TIMED_WAITING on java