com.atlassian.threadlocal
Class RegisteredThreadLocal<T>

java.lang.Object
  extended by java.lang.ThreadLocal<T>
      extended by com.atlassian.threadlocal.RegisteredThreadLocal<T>

public class RegisteredThreadLocal<T>
extends java.lang.ThreadLocal<T>

A ThreadLocal class that registers itself with RegisteredThreadLocals and hence can be automatically cleaned up at the end of a request.


Constructor Summary
RegisteredThreadLocal()
           
 
Method Summary
protected  T initialValue()
          We use lazy registration so that any time this method or set(Object) is called we register with this threads RegisteredThreadLocals.
 void set(T value)
           
protected  T supplyInitialValue()
          Alternate template method for supplying the initial value
 
Methods inherited from class java.lang.ThreadLocal
get, remove
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RegisteredThreadLocal

public RegisteredThreadLocal()
Method Detail

initialValue

protected final T initialValue()
We use lazy registration so that any time this method or set(Object) is called we register with this threads RegisteredThreadLocals. But because this is a template method that we cant intercept we need to force you to supply the initial value via another template method. Sorry about this. It smells but its the way it has to be.

Overrides:
initialValue in class java.lang.ThreadLocal<T>
Returns:
an initial value, while lazy registering the ThreadLocal

supplyInitialValue

protected T supplyInitialValue()
Alternate template method for supplying the initial value

Returns:
an initial value

set

public void set(T value)
Overrides:
set in class java.lang.ThreadLocal<T>


Copyright © 2013 Atlassian. All Rights Reserved.