2 Replies Latest reply on May 21, 2004 11:47 AM by starksm64

    Creating Threads in EJBs

    tamcor

      I believe the EJB spec recommends not creating your own threads in EJBs, but I have a case where this seems to be the best solution. Can anyone let me know if this is safe to do in JBoss, and if it is, how to go about coding them safely.

      In particular, I am concerned about what happens when the EJB is passivated and if there is a way to tell JBoss not to passivate if the thread is still active.

      Also I found this from a newsgroup on this topic, but there was no further explanation:
      >> JBoss needs an ugly hack (a static method needs to be called) to set the proper security context on a thread.

      Thanks for your help/thoughts.

        • 1. Re: Creating Threads in EJBs
          darranl

          The EJB Spec does not reccomend that that EJBs should not create threads, the spec says that EJBs must not create threads.

          The argument the spec gives for this is so that the container can manage the runtime enviroment, your second point proves the need for this restriction.

          Is there no way that you could use a message driven bean or possible a MBean for this?

          • 2. Re: Creating Threads in EJBs
            starksm64

            The only way it can be done safely is too create a customization of the ejb container such that any interaction goes through the ejb container interceptor stack to correctly deal with the security, caching, passivation, synchronization, etc. behavior required. If you don't want this extra behavior, configure your own custom container with the interceptors that provide the semantics you want. Your not doing EJBs at that point.