protected final ThreadingContext initialValue ()
{
synchronized (this) {
try {
this.initialValueActive = true;
ThreadingContext context = super.initialValue ();
final Thread thread = Thread.currentThread ();
if (context == null) {
if (thread instanceof ManagedThread) {
context = ((ManagedThread) thread).getContext ();
Preconditions.checkNotNull (context);
}
}
if (context == null) {
for (ThreadGroup group = thread.getThreadGroup (); group != null; group = group.getParent ())
if (group instanceof ManagedThreadGroup) {
context = ((ManagedThreadGroup) group).getContext ();
Preconditions.checkNotNull (context);
break;
}
}
if (context != null) {
if (!context.isManaged (thread))
context.registerThread (thread);
}
return (context);
} finally {
this.initialValueActive = false;
}