While troubleshooting one of the jvm hung issues in our production environment, we encountered that one of threads which executes the following logger statement
logger.debug("Loaded ids as " + ids + ".");
is hung at this step with the thread status as runnable. Here ids is a Set. There is another thread which waits on the above thread through a count down latch to complete its task. The software takes thread dumps every 15 mins and the stacktraces of the two threads look as below
Stack trace for [THREAD GROUP: Job_Executor] [THREAD NAME:main-Runner Thread][THREAD STATE: WAITING]
...sun.misc.Unsafe.park(Native Method)
...java.util.concurrent.locks.LockSupport.park(Unknown Source)
...java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(Unknown Source)
...java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedInterruptibly(Unknown Source)
...java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(Unknown Source)
...java.util.concurrent.CountDownLatch.await(Unknown Source)
...com.runner.MainRunner.stopThread(MainRunnerRunner.java:1334)
Stack trace for [THREAD GROUP: Job_Executor] [THREAD NAME:task executor][THREAD STATE: RUNNABLE]
...java.util.AbstractCollection.toString(Unknown Source)
...java.lang.String.valueOf(Unknown Source)
...java.lang.StringBuilder.append(Unknown Source)
...com.runner.CriticalTaskExecutor.loadByIds(CriticalTaskExecutor.java:143)
This jvm got hung for almost 24 hrs and finally we had to kill it to move ahead. The thread dumps indicates that there are 43 threads in RUNNABLE state including the above one.
What could be the reasons for the above thread to be in RUNNABLE state for 24 hrs just executing collection.toString()?
Any suggestions on how to proceed?
It depends on the
toString()
method that's being called. I've seenAbstractCollection.toString
fall over when theString
being constructed is too large for the heap. Otherwise, the problem could be in thetoString
of the objects in the collection.To figure out which one it is, take some more stack dumps (10 or so). The stuck thread will probably usually be in the
toString
that's causing the problem.As a quick fix, replace
with
(Assuming you're using slf4j, otherwise look up the appropriate way to do parameterized logging in your framework).
This will skip the toString if debug is not enabled.