org.rhq.enterprise.server.util
Class LoggingThreadFactory

java.lang.Object
  extended by org.rhq.enterprise.server.util.LoggingThreadFactory
All Implemented Interfaces:
Thread.UncaughtExceptionHandler, ThreadFactory

public class LoggingThreadFactory
extends Object
implements ThreadFactory, Thread.UncaughtExceptionHandler

This thread factory just adds a Thread.UncaughtExceptionHandler to threads it creates so that there are logs of the exceptions that cause threads to die.

Use this class when providing a thread factory to threadpools.

This factory's constructor can be told to create daemon or non-daemon threads.

Author:
Greg Hinkle

Constructor Summary
LoggingThreadFactory(String poolName, boolean daemon)
          Creates a factory that will produce either daemon or non-daemon threads.
 
Method Summary
 Thread newThread(Runnable r)
           
 void uncaughtException(Thread t, Throwable e)
          This simply logs the exception via this factory's logger.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LoggingThreadFactory

public LoggingThreadFactory(String poolName,
                            boolean daemon)
Creates a factory that will produce either daemon or non-daemon threads. Be careful if you pass in false for the daemon parameter; if you do, make sure your thread pool and all its threads created by this factory are properly shutdown; otherwise you could prevent the VM from exiting properly.

Parameters:
poolName - the name of the thread pool that will be using this factory
daemon - if true, the factory will create daemon threads; false for non-daemon threads
Method Detail

newThread

public Thread newThread(Runnable r)
Specified by:
newThread in interface ThreadFactory
See Also:
ThreadFactory.newThread(Runnable)

uncaughtException

public void uncaughtException(Thread t,
                              Throwable e)
This simply logs the exception via this factory's logger.

Specified by:
uncaughtException in interface Thread.UncaughtExceptionHandler
See Also:
Thread.UncaughtExceptionHandler.uncaughtException(Thread, Throwable)


Copyright © 2008-2012 Red Hat, Inc.. All Rights Reserved.