Ok, I have a better understanding of ThreadLocal variables now.Hi, there were some problems with multi-threading and the environment stack which should be fixed by last monday - at least that's what I thought.However, there is one subtle thing to keep in mind: ThreadLocal and InheritableThreadLocal variables! The current environment stack uses a InheritableThreadLocal variable - so you have to make sure that if you create/use a different thread that this InheritableThreadLocal variable is initialized correctly. Especially when you use thread-pools you have to manually set this variable (contained in the CocoonComponentManager) whenever you take a thread out of the pool and use it.
Would you mind giving a quick example of how to do this?
I've been poring over the source, but I'm not sure I'm on the right track:
//code run by PooledThread
public void run() {
Environment env = CocoonComponentManager.getCurrentEnvironment();
Processor proc = CocoonComponentManager.getCurrentProcessor();
CoccoonComponentManager.startProcessing(env);
CoccoonComponentManager.enterEnvironment(env);
doStuff();
CoccoonComponentManager.leaveEnvironment();
}
As far as thread safety goes, I know my own code doesn't have ThreadLocals, but I don't know where else in the Cocoon machinery they might lurk.
Thanks for your help,
Greg