What should we avoid in thread dumps
One of the most common trick is knowing what to ignore safely. Let’s have a look at sample thread dump:
"Atmosphere-Scheduler-3162" nid=137911 state=TIMED_WAITING  java.lang.Thread.State: TIMED_WAITING - waiting on <0x2db6a729> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject) - locked <0x2db6a729> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject) at sun.misc.Unsafe.park(Native Method) 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.poll(ScheduledThreadPoolExecutor.java:1129) at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.poll(ScheduledThreadPoolExecutor.java:809) at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1073) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748)
If you look at the stack trace you will notice the usage of the LockSupport.parkNanos method. We are here actually in the case of a parked thread. A parked thread is disabled for scheduling until it gets a “permit” from a another thread, that will allow it to start executing again, or it will restart when the timeout value has been reached.
If we look further down the stack trace we see that we are actually inside a ThreadPoolExecutor, that is basically waiting for a new task. So in effect this thread is just waiting for a task to execute, this means that we can basically ignore it from our analysis since it is not going to affect our performance in any way.
This is a good first example of threads that can be ignored in our analysis. Another example are threads that are waiting for a request, such as a pool of HTTP threads that are just waiting for an incoming request. Although it looks like they are holding locks and waiting on monitors they are actually just parked threads and we can safely ignore them.