I am debugging a live environment and I have taken some thread dumps. I see that lot of thread are "waiting on condition"; but how can I know what that condition is?
The below is the snippet of real thread dump stack:
"Uploader-pool-job-create-ca2d264a-51b3-4fa3-8113-
f0f0aca47add-StreamThread-10-0_14" #140 daemon prio=5 os_prio=0
tid=0x00007f006002b800 nid=0x18b waiting on condition
[0x00007f004d9e1000]
java.lang.Thread.State: TIMED_WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000002c20d4320> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078)
at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1093)
at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1067)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Other:
"Uploader-pool-job-create-ca2d264a-51b3-4fa3-8113-
f0f0aca47add-StreamThread-3-0_16" #138 daemon prio=5 os_prio=0
tid=0x00000000025da000 nid=0x189 waiting on condition
[0x00007f004dbe3000]
java.lang.Thread.State: TIMED_WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000002c20d6690> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078)
at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1093)
at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1067)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
In these threads it is saying "waiting on condition"; but I can't decipher what that condition is on which the thread is waiting on?
--> In general, are there any guidelines how to understand thread dumps.
It's all there in the stack trace - ScheduledThreadPoolExecutor
is awaiting on the available
condition:
private final Condition available;
. . .
available.awaitNanos(delay); // ScheduledThreadPoolExecutor.java:1093
In other words, the thread in the pool is idle and waiting for more work.
In general, the stack trace shows exactly the Java file name and line number where the thread of execution is currently at (usually when a thread is waiting, the deepest few levels would be too low-level, so just continue up the chain to find the most meaningful level).