edu.emory.mathcs.util.concurrent
Class ExecutorUtils.SafeThreadFactory

java.lang.Object
  extended byedu.emory.mathcs.util.concurrent.ExecutorUtils.SafeThreadFactory
All Implemented Interfaces:
ThreadFactory
Enclosing class:
ExecutorUtils

public static class ExecutorUtils.SafeThreadFactory
extends java.lang.Object
implements ThreadFactory

Thread factory implementation that attempts to ensure that created threads are equivalent regardless of threads that request creation. Precisely, created threads belong to the same thread group, and they inherit a "parent thread context" (access control context, DelegatableThreadLocals, etc.) from the factory creator rather than from the invoker of newThread(java.lang.Runnable).

When used with ThreadPoolExecutor, is ensures deterministic behavior and consistent security properties. Nevertheless, stronger semantics are often neccessary in security-sensitive applications. In particular, it may be required that worker tasks run within access control context and with delegatable locals of the thread that scheduled the task, which may generally be distinct from both the thread pool creator and the worker thread creator. If such security semantics is needed, use SecureThreadPoolExecutor.

Version:
1.0
Author:
Dawid Kurzyniec

Constructor Summary
ExecutorUtils.SafeThreadFactory()
          Creates a new tread factory that creates threads within a default thread group.
ExecutorUtils.SafeThreadFactory(java.lang.String name)
          Creates a new tread factory that uses default thread group and specified thread name prefix.
ExecutorUtils.SafeThreadFactory(java.lang.ThreadGroup group)
          Creates a new tread factory that creates threads within the specified thread group.
ExecutorUtils.SafeThreadFactory(java.lang.ThreadGroup group, java.lang.String name)
          Creates a new tread factory that creates threads within the specified thread group, and uses specified thread name prefix, appending consecutive numbers to the names of created threads.
ExecutorUtils.SafeThreadFactory(java.lang.ThreadGroup group, java.lang.String name, boolean count)
          Creates a new tread factory that creates threads within the specified thread group, and uses specified thread name prefix.
 
Method Summary
 java.lang.Thread newThread(java.lang.Runnable command)
          Constructs a new Thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExecutorUtils.SafeThreadFactory

public ExecutorUtils.SafeThreadFactory()
Creates a new tread factory that creates threads within a default thread group. The group of the current thread (invoking this constructor) is used as a default unless explicitly overridden by current security manager.


ExecutorUtils.SafeThreadFactory

public ExecutorUtils.SafeThreadFactory(java.lang.String name)
Creates a new tread factory that uses default thread group and specified thread name prefix. The group of the current thread (invoking this constructor) is used as a default unless explicitly overridden by current security manager.

Parameters:
name - the thread name prefix

ExecutorUtils.SafeThreadFactory

public ExecutorUtils.SafeThreadFactory(java.lang.ThreadGroup group)
Creates a new tread factory that creates threads within the specified thread group.

Parameters:
group - the thread group for created threads

ExecutorUtils.SafeThreadFactory

public ExecutorUtils.SafeThreadFactory(java.lang.ThreadGroup group,
                                       java.lang.String name)
Creates a new tread factory that creates threads within the specified thread group, and uses specified thread name prefix, appending consecutive numbers to the names of created threads.

Parameters:
group - the thread group for created threads
name - the thread name prefix

ExecutorUtils.SafeThreadFactory

public ExecutorUtils.SafeThreadFactory(java.lang.ThreadGroup group,
                                       java.lang.String name,
                                       boolean count)
Creates a new tread factory that creates threads within the specified thread group, and uses specified thread name prefix.

Parameters:
group - the thread group for created threads
name - the thread name prefix
Method Detail

newThread

public java.lang.Thread newThread(java.lang.Runnable command)
Description copied from interface: ThreadFactory
Constructs a new Thread. Implementations may also initialize priority, name, daemon status, ThreadGroup, etc.

Specified by:
newThread in interface ThreadFactory
Parameters:
command - a runnable to be executed by new thread instance
Returns:
constructed thread