Pretty much the tcl is set whenever a call enters into a container, be it jmx, ejb, web. Its needed when transitioning from the microkernel into a deployment context that can introduce new classes or class versions due to a deployment.
It would generally seem that the TCL is the more typical level at which you would want to associate aspects as at least the metadata is likely to be coming from the application context. I have been noticing some issues with using the TCL as a key due to the fact that we tend to have noop class loaders to differentiate deployment contexts, and it can be a little hard to control how certain searches for resources behave. Another thing that is difficult is cleaning up classes on redeployment. The java.lang.ClassLoader in at least sun's impl has a private array of the classes loaded that cannot be cleared by subclasses. What I'm seeing with extensive holders of the TCL is that its difficult to clear everything, and this can lead to the use of stale classes, and leaks when frameworks make use of caches keyed to class statics.
Because there are a fair number of issues with the current class loading that cannot be changed, I'm thinking that we need to be looking at another thread context at the key rather than the thread context class loader.
I've been thinking about this over the weekend, and what I think I"m going to add is the expansion of CFLOW. Currently CFLOW only looks at the Java call stack. I think I will expand it to look at our metadata chain, or configuration domains.
So, instead of just a method or contstructor within the call stack, it will try to resolve a metadata reference from the metadata chain. Since ThreadMetaData is in the metadata chain you can set up custom CFLOWs.
One thing about this is that we'll probably want "stacked" ThreadMetaData. FOr instance, if we use ThreadMetaData to tag application boundaries, you'll probably be interested in previous values of this threadlocal value.
well Scott is talking about just an abstract keyword (thread local) to identify a given configuration. Is that what you are talking about.