Title: Java Thread States — Lock During I/O Causes BLOCKED
Open Graph Title: Java Thread States — Lock During I/O Causes BLOCKED
Description: A 30-second 503? Check thread dumps for BLOCKED threads on a lock held during I/O — exactly the real production incident we decode step by step.
Open Graph Description: A 30-second 503? Check thread dumps for BLOCKED threads on a lock held during I/O — exactly the real production incident we decode step by step.
Opengraph URL: https://thecodeforge.io/java/thread-lifecycle-java/
Domain: thecodeforge.io
{
"@context": "https://schema.org",
"@type": "TechArticle",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "https://thecodeforge.io/java/thread-lifecycle-java/"
},
"headline": "Java Thread States — Lock During I/O Causes BLOCKED",
"description": "A 30-second 503? Check thread dumps for BLOCKED threads on a lock held during I/O — exactly the real production incident we decode step by step.",
"keywords": "Java Thread States — Lock During I/O Causes BLOCKED, Java, Advanced, Multithreading, A 30-second 503? Check thread dumps for BLOCKED threads on a lock held during I/O — exactly the real production incident we decode step by step.",
"proficiencyLevel": "Expert",
"author": {
"@type": "Person",
"@id": "https://thecodeforge.io/about/#naren",
"name": "Naren",
"url": "https://thecodeforge.io/about/"
},
"publisher": {
"@type": "Organization",
"@id": "https://thecodeforge.io/#org",
"name": "TheCodeForge",
"url": "https://thecodeforge.io",
"logo": {"@type": "ImageObject", "url": "https://thecodeforge.io/assets/og-image.png"}
},
"datePublished": "2026-03-05T00:00:00+00:00",
"dateModified": "2026-08-30T00:00:00+00:00",
"url": "https://thecodeforge.io/java/thread-lifecycle-java/",
"inLanguage": "en",
"educationalLevel": "Advanced",
"image": "https://thecodeforge.io/assets/og-image.png",
"isPartOf": {"@id": "https://thecodeforge.io/#website"}
}
{
"@context": "https://schema.org",
"@type": "BreadcrumbList",
"itemListElement": [
{"@type": "ListItem", "position": 1, "name": "Home", "item": "https://thecodeforge.io/"},
{"@type": "ListItem", "position": 2, "name": "Java", "item": "https://thecodeforge.io/java/"},
{"@type": "ListItem", "position": 3, "name": "Java Thread States — Lock During I/O Causes BLOCKED", "item": "https://thecodeforge.io/java/thread-lifecycle-java/"}
]
}
{
"@context": "https://schema.org",
"@type": "FAQPage",
"mainEntity": [
{
"@type": "Question",
"name": "What is the difference between sleep() and wait() in Java threads?",
"acceptedAnswer": {
"@type": "Answer",
"text": "sleep() is a static method on Thread. It makes the current thread pause for a specified time, but does not release any locks it holds. It puts the thread in TIMED_WAITING state. wait() is an instance method on Object. It must be called from a synchronized context and releases the lock associated with that object. The thread goes to WAITING (or TIMED_WAITING if timeout specified) until another thread calls notify()/notifyAll() on the same object."
}
},
{
"@type": "Question",
"name": "Why does 'jstack' show a thread as RUNNABLE when it's waiting for network I/O?",
"acceptedAnswer": {
"@type": "Answer",
"text": "Because the thread is not blocked by a Java monitor — it's blocked at the OS level. The JVM considers it RUNNABLE because the underlying native thread is still scheduled and waiting for a system call to return. For example, java.net.SocketInputStream.socketRead0 is a native method. The OS may block the thread inside that native call, but from the JVM's perspective, the thread is still executing (RUNNABLE). This is a common source of confusion."
}
},
{
"@type": "Question",
"name": "Can a thread move directly from RUNNABLE to TERMINATED without going through WAITING/BLOCKED?",
"acceptedAnswer": {
"@type": "Answer",
"text": "Yes, if the thread's run() method completes without encountering any blocking operations. The thread goes from RUNNABLE (executing the body) to TERMINATED. It never enters WAITING or BLOCKED. This is typical for short-lived threads with no synchronization."
}
},
{
"@type": "Question",
"name": "What is a spurious wakeup?",
"acceptedAnswer": {
"@type": "Answer",
"text": "A spurious wakeup is when a thread returns from wait() without being notified, interrupted, or timed out. The JVM specification allows this to happen (usually due to OS-level signals). This is why you must always call wait() inside a while loop that checks the condition, not an if statement."
}
},
{
"@type": "Question",
"name": "How can I see thread states in production without killing the process?",
"acceptedAnswer": {
"@type": "Answer",
"text": "Use jstack (produces a text dump to stdout). Or use jcmd Thread.print. For Kubernetes, use kubectl exec -- jstack 1. For Java Flight Recorder (JFR), you can capture thread dumps in a recording. All are safe to run without interrupting the JVM."
}
}
]
}
| og:type | website |
| og:image | https://thecodeforge.io/assets/og-image.png |
| og:image:width | 1200 |
| og:image:height | 630 |
Links:
Viewport: width=device-width, initial-scale=1.0
Robots: max-image-preview:large