cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Weinger <gwein...@itmedicine.net>
Subject Re: [SHOWSTOPPER?] cocoon sources no longer thread-safe
Date Thu, 05 Dec 2002 02:38:31 GMT
  Carsten Ziegeler wrote:

>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.
>  
>
Ok, I have a better understanding of ThreadLocal variables now.  

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

Mime
View raw message