Growing amount of TimerThreads
環境
- JBoss Enterprise Application Platform (EAP)
- Java
問題
-
We have a constantly growing amount of idle TimerThreads in our JVM:
"Timer-252" daemon prio=10 tid=0x00002ace41acc000 nid=0x138a in Object.wait() [0x00002ace6b873000] java.lang.Thread.State: TIMED_WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x00000000fd09e810> (a java.util.TaskQueue) at java.util.TimerThread.mainLoop(Timer.java:509) - locked <0x00000000fd09e810> (a java.util.TaskQueue) at java.util.TimerThread.run(Timer.java:462) -
How can we troubleshoot and resolve this?
解決策
- Be sure to reuse a Timer object if you can.
- If you are done with a Timer object, be sure you call
Timer.cancel()and that references are removed so the Timer can be GC'd.
原因
- New
java.util.Timerobjects are being created repeatedly and are not being cancelled or freed from the heap. A TimerThread persists until thejava.util.Timerthat the thread belongs to is cancelled with a Timer.cancel() call or until the Timer object is GC'd and finalized.
診断手順
-
For debugging, consider giving a unique name to any Timers you create:
Timer t = new Timer("UniqueTimerName");The TimerThreads will get this same unique name in thread dumps then for better tracking of which Timers are growing rather than a generic Timer-123 name, which is the default.
- Since the TimerThreads are still in their mainloop, we know the Timer's have not been finalized or GC'd. Thus, we could likely see who has references to the leaked Timers through a heap dump. You should capture a heap dump from a time of high timer build up. You can capture a heap dump with your JDK's jmap command as explained in How do I create a Java heap dump?.
このソリューションは、Red Hat のエンジニアがお客様のサポート中に作成したナレッジコンテンツの大型ライブラリーを提供する Fast-Track Publication Program の一環です。お客様が必要とする知識・情報を即時に提供するために、これらの記事は、未処理・未編集の状態で提示される場合がありますので、予めご了承ください。
コメント