Greg Weinger wrote: > 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(); > } > Ok, it's a little bit difficult. First, the thread you create is not allowed to run longer than the original thread - but I guess that's not the case for you anyway. Second, the thread runs in the same environment as the original thread.
Regarding the ThreadLocal variable, you have to clone it first from the original thread. The CocoonComponentManager has a private static variable: private static InheritableThreadLocal environmentStack; You have to set this in your "new" thread (taken from the pool) to a clone! of the parent thread. The clone() method can be used for this. And then something like this: public void run() { Environment env = CocoonComponentManager.getCurrentEnvironment(); Object key = CocoonComponentManager.startProcessing(env); CocoonComponentManager.enterEnvironment(env); try { doStuff(); } finally { CocoonComponentManager.leaveEnvironment(); CocoonComponentManager.endProcessing(env, key); } } This should work...hopefully... > >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. > In Cocoon itself there are afaik no more ThreadLocals, but in theory you also have to check Xalan, Xerces, FOP and every other library you use - and that's impossible. So you can start with the ThreadLocal of Cocoon and hope that you don't get problems :) Isn't life easy? HTH Carsten Carsten Ziegeler Open Source Group, S&N AG --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED]