Classes | Public Member Functions | Static Public Attributes | Protected Attributes | Package Functions

alma.acs.container.CleaningDaemonThreadFactory Class Reference

Inherits java::util::concurrent::ThreadFactory.

List of all members.

Classes

class  LoggingThreadGroup

Public Member Functions

 CleaningDaemonThreadFactory (String name, Logger logger)
 CleaningDaemonThreadFactory (String name, Logger logger, String ownerName)
Thread newThread (Runnable command)
List< Thread > _getAllThreadsCreated ()
synchronized void cleanUp ()

Static Public Attributes

static final String LOG_THREAD_CREATION_CALLSTACK_PROPERTYNAME = "alma.acs.threadfactory.trace_creators"

Protected Attributes

boolean logThreadCreationCallstack = Boolean.getBoolean(LOG_THREAD_CREATION_CALLSTACK_PROPERTYNAME)

Package Functions

void setNewThreadContextClassLoader (ClassLoader cl)

Detailed Description

Thread factory that remembers all threads it creates. Method cleanUp allows killing all threads.

A ThreadGroup is used to deal with all threads at a time. Its name is that given in the constructor. Even though Josh Bloch tells us in "Effective Java", Item 53, that thread groups are almost useless, we like the UncaughtExceptionHandler which JDK 1.4 only offers through ThreadGroups. TODO: revisit this in JDK 1.5 where Thread itself has this handler.

Author:
hsommer created Mar 8, 2005 1:27:38 PM

Constructor & Destructor Documentation

alma.acs.container.CleaningDaemonThreadFactory.CleaningDaemonThreadFactory ( String  name,
Logger  logger 
)

Normal constructor.

Parameters:
name the name of the ThreadGroup to which all threads created by this factory will belong.
logger the logger to be used by this class
alma.acs.container.CleaningDaemonThreadFactory.CleaningDaemonThreadFactory ( String  name,
Logger  logger,
String  ownerName 
)

Special constructor, e.g. when used internally by the container.

Parameters:
name the name of the ThreadGroup to which all threads created by this factory will belong.
logger the logger to be used by this class
ownerName Can show up in log messages such as warnings by LoggingThreadGroup#uncaughtException(Thread, Throwable).

Member Function Documentation

List<Thread> alma.acs.container.CleaningDaemonThreadFactory._getAllThreadsCreated (  ) 

Gets a copy of the list of all threads created by this factory up to this call. This method should only be used for testing, but not in operational code.

synchronized void alma.acs.container.CleaningDaemonThreadFactory.cleanUp (  ) 

Kills running threads via Thread#interrupt() or Thread#stop(), see code comments about the two cases. Should be called by the container or similar classes when all threads created by this factory supposedly have terminated anyway thanks to smart applications. The safety concerns which led to the deprecation of the stop method thus don't seem to apply here.

Referenced by alma.acs.container.ComponentAdapter.deactivateComponent(), alma.acs.container.ComponentAdapter.getComponentAbortionist(), alma.acs.component.client.ComponentClientTestCase.tearDown(), and alma.acs.component.client.ComponentClient.tearDown().

Thread alma.acs.container.CleaningDaemonThreadFactory.newThread ( Runnable  command  ) 

Creates a new daemon thread that is part of the same factory thread group as all other threads created by this method. The thread's name will be that of the group, with an integer value appended.

See also:
java.util.concurrent.ThreadFactory.newThread(java.lang.Runnable)

References alma.acs.container.CleaningDaemonThreadFactory.logThreadCreationCallstack.

void alma.acs.container.CleaningDaemonThreadFactory.setNewThreadContextClassLoader ( ClassLoader  cl  )  [package]

Member Data Documentation

final String alma.acs.container.CleaningDaemonThreadFactory.LOG_THREAD_CREATION_CALLSTACK_PROPERTYNAME = "alma.acs.threadfactory.trace_creators" [static]

If this property is set to true, the creators of new threads will be identified through a INFO log showing the calling stack trace, which helps for example in finding out who created a thread but later fails to clean it up (see logs "Forcibly terminating surviving thread ...").


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Enumerations Properties