Creating the context pattern is easy when wrapping a ThreadLocal in a bean and wiring up the bean wherever you need it. That's what I meant with seeing where the ThreadLocal is used.
Yes, the danger of using a ThreadLocal is that you're creating global variables, but that's only the case when using them in a static fashion.
Think of something like this:
Code:
// somewhat like the contextholder Acegi uses
public void Context {
private ThreadLocal tl = new ThreadLocal();
public void setContextObject(ContextObject o) {
this.tl.set(o);
}
public void reset() {
this.tl.set(null);
}
}
public class BusinessObject {
private Context context;
public void setContext(Context c) { .. }
}
<bean class="BusinessObject">
<property name="context"><ref bean="context"/></property>
</bean>
<bean id="context" class="Context"/>
This way, you (have to) wire up the context whereever you need it and it's clear that the business object is using it.
regards,
Alef