org.apache.myfaces.trinidad.util
Class ThreadLocalUtils

java.lang.Object
  extended by org.apache.myfaces.trinidad.util.ThreadLocalUtils

public final class ThreadLocalUtils
extends Object

Utility functions related to ThreadLocals. This class provides utilities for managing the lifecycles of ThreadLocals. In particular, many application servers do not clean up the ThreadLocals added to the request thread before returning the request thread to its thread pool. This may have several severe side-effects, including

  1. Leakage of objects referenced by the thread local
  2. Possible security holes if the ThreadLocals contents are reused on a request for a different user.
  3. Leakage of the entire class loader in live patching scenarios
  4. ClassCastExceptions in live patching scenarios
To avoid these problems, this class provides utilities for creating and registering ThreadLocals that will be removed from the thread automatically at the end of the current request.

See Also:
newRequestThreadLocal(), registerRequestThreadLocal(java.lang.ThreadLocal)

Nested Class Summary
static class ThreadLocalUtils.ThreadLocalLifecycle
          Integration interface implemented by an object that cleans up the ThreadLocals in a ThreadLocalManager with the specified lifetime.
static class ThreadLocalUtils.ThreadLocalManager
          Integration interface implemented by object holding onto ThreadLocals with a specified lifetime
 
Method Summary
static
<T> ThreadLocal<T>
newRequestThreadLocal()
          Creates and returns a new ThreadLocal that will be automatically removed from the each request thread when the request finishes.
static
<T> ThreadLocal<T>
registerRequestThreadLocal(ThreadLocal<T> threadLocal)
          Registers and returns the ThreadLocal to be automatically removed from the each request thread when the request finishes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

newRequestThreadLocal

public static <T> ThreadLocal<T> newRequestThreadLocal()
Creates and returns a new ThreadLocal that will be automatically removed from the each request thread when the request finishes.

Returns:
The ThreadLocal
See Also:
registerRequestThreadLocal(java.lang.ThreadLocal)

registerRequestThreadLocal

public static <T> ThreadLocal<T> registerRequestThreadLocal(ThreadLocal<T> threadLocal)
Registers and returns the ThreadLocal to be automatically removed from the each request thread when the request finishes.

Parameters:
threadLocal - ThreadLocal to register for automatic removal
Returns:
The reigistered ThreadLocal
See Also:
newRequestThreadLocal()


Copyright © 2001-2012 The Apache Software Foundation. All Rights Reserved.