org.apache.avalon.excalibur.lang
Class ThreadContext
java.lang.Object
|
+--org.apache.avalon.excalibur.lang.ThreadContext
- public final class ThreadContext
- extends java.lang.Object
The ThreadContext defines a set of data that is associated
with a particular thread. In particular this is useful as a
location to centralize management of ThreadLocal-type variables.
As such the type of data contained in ThreadContext
is usually data such as ContextClassLoader, Transaction ID,
User ID/Subject, etc. Note that these ThreadLocal variables may
not actually be implemented using the ThreadLocal
class but need to model such behaviour.
These variables are managed by the ThreadContext. However as it
is not possible to inject code to be executed at the start of a
thread, new threads may not be activated and the variables may not
be set appropriately. In such cases it is recomended that the developer
use InheritableThreadLocal
as the underlying representation
of the variable. By doing this the InheritableThreadLocal
will maintain the appropriate state in newly created Thread.
The policy chosend to manage such state is pluggable by the user.
It is expected developers will provide a policy object that will manage
thread local variables. For instance an application server may choose to
keep the name of the application, the Subject it is running as and perhaps
other state in such variables.
- Author:
- Peter Donald
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ThreadContext
public ThreadContext(ThreadContextPolicy policy,
java.util.Map map)
- Constructor that places values specified in
Map
into ThreadContext
.
- Parameters:
map
- the Map
getThreadContext
public static ThreadContext getThreadContext()
- Retrieve the ThreadContext associated with the current thread.
- Returns:
- the ThreadContext associated with the current thread.
setThreadContext
public static void setThreadContext(ThreadContext threadContext)
throws java.lang.SecurityException
- Set the ThreadContext associated with the current thread.
This code will also call
deactivate()
on the old
ThreadContext
if present and activate()
on new ThreadContext
(if not null).
- Parameters:
threadContext
- the new ThreadContext- Throws:
java.lang.SecurityException
- if the caller does not have permission to set thread pool
Copyright © 2001 Apache Jakarta Project. All Rights Reserved.