Thread local variables within EJBs?


EJB design: Thread local variables within EJBs?

  1. Thread local variables within EJBs? (2 messages)

    I'd like to be able to make the EJBContext visible to all the classes which form my EJB implememtation without explicitly passing it as a parameter.

    Can I use a ThreadLocal to do this?

    My plan is that I'd assign the context to a ThreadLocal at the start of each EJB member function.

    Will this work?

  2. There is no prohibition to using ThreadLocal or InheritableThreadLocal within EJB's. The EJB methods must themselves necessarily use conventional Java call semantics to call other methods. As long as you do nothing that could trigger the use of a different thread, you ThreadLocal will be visible. If it is all code you wrote and you don't expect this behavior across invocations of other EJB's, you are fine.

    I have done things like this in WebLogic, Orion and JBoss. No problems.
  3. what about cross-instance calls?[ Go to top ]

    so what do you do if your ejb has to make a remote call (cross-jvm) to another ejb and you want some object passed thru implicitely (not as a method param).

    is this even possible and how?