com.yammer.metrics.util
Class DeathRattleExceptionHandler

java.lang.Object
  extended by com.yammer.metrics.util.DeathRattleExceptionHandler
All Implemented Interfaces:
Thread.UncaughtExceptionHandler

public class DeathRattleExceptionHandler
extends Object
implements Thread.UncaughtExceptionHandler

When a thread throws an Exception that was not caught, a DeathRattleExceptionHandler will increment a counter signalling a thread has died and print out the name and stack trace of the thread.

This makes it easy to build alerts on unexpected Thread deaths and fine grained used quickens debugging in production.

You can also set a DeathRattleExceptionHandler as the default exception handler on all threads, allowing you to get information on Threads you do not have direct control over.

Usage is straightforward:

 CounterMetric c = Metrics.newCounter(MyRunnable.class, "thread-deaths")
 Thread.UncaughtExceptionHandler exHandler = new DeathRattleExceptionHandler(c)
 Thread myThread = new Thread(myRunnable, "MyRunnable")
 myThread.setUncaughtExceptionHandler(exHandler)
 

Setting the global default exception handler should be done first, like so:

 CounterMetric c = Metrics.newCounter(MyMainClass.class, "unhandled-thread-deaths")
 Thread.UncaughtExceptionHandler ohNoIDidntKnowAboutThis = new DeathRattleExceptionHandler(c)
 Thread.setDefaultUncaughtExceptionHandler(ohNoIDidntKnowAboutThis)
 


Constructor Summary
DeathRattleExceptionHandler(CounterMetric deathRattle)
           
 
Method Summary
 void uncaughtException(Thread t, Throwable e)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DeathRattleExceptionHandler

public DeathRattleExceptionHandler(CounterMetric deathRattle)
Method Detail

uncaughtException

public void uncaughtException(Thread t,
                              Throwable e)
Specified by:
uncaughtException in interface Thread.UncaughtExceptionHandler


Copyright © 2011. All Rights Reserved.