Lifecycle and interpreting thread dumps
Definition:
A Java thread state describes execution or waiting from the JVM’s perspective.
Explanation:
A Java RUNNABLE state is not direct proof of CPU consumption; it can also appear during native activity.
Illustration image:
Example:
Thread t = new Thread(() -> System.out.println("worker"), "example-worker");
System.out.println(t.getState()); // NEW
t.start();
t.join();
System.out.println(t.getState()); // TERMINATEDExpected behavior. join establishes an observation boundary; do not assert an intermediate state with a sleep.
Internal working:
BLOCKED denotes intrinsic monitor acquisition, while a thread parked by a ReentrantLock commonly appears WAITING. Compare several dumps and CPU samples. Inspect lock identity and owning thread instead of diagnosing from names alone.
Interview questions:
Does RUNNABLE mean a thread is consuming CPU?
No. It can also be eligible to run or in a native operation. Compare stacks and CPU samples.