最近新写一个程序发现负载很高,不知原因,故使用jstack将线程信息打印出来。找到给900多个等待如下资源的线程: - parking to wait for <0x00007f126138b7e0> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject) 查了一圈资料,好像是说在等队列进来,难道是线程池单纯太大,引起上下文切换和管理引起的CPU高?! I noticed that my java application (runs on tomcat6) spawns a lot of threads which do not terminate.
So I created a thread dump and noticed that there are tons of threads waiting, like this:
"pool-1-thread-22" prio=5 tid=101b4b000 nid=0x127122000 waiting on condition [127121000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <6c340cee0> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:156)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:1987)
at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:399)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:947)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
at java.lang.Thread.run(Thread.java:680)
Locked ownable synchronizers:
- None
Now the question is: WHAT are these threads waiting for?
I have suspect class which seems to spawn these threads but I don't know what exactly is making these threads stuck.
Is there anything I can do to find the cause for this except for tearing the class apart line by line and keep monitoring thread behavior?
|