Growing amount of TimerThreads

Solution Unverified - Updated -

Environment

  • JBoss Enterprise Application Platform (EAP)
  • Java

Issue

  • 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?

Resolution

  • 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.

Root Cause

  • New java.util.Timer objects are being created repeatedly and are not being cancelled or freed from the heap. A TimerThread persists until the java.util.Timer that the thread belongs to is cancelled with a Timer.cancel() call or until the Timer object is GC'd and finalized.

Diagnostic Steps

  • 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?.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.