1 Reply Latest reply on Dec 30, 2010 3:42 AM by jaikiran

    Create stateless bean from stateful bean

    piotrekde

      Hi,

       

      It is a simple question (however I'm not sure about the answer). In my application there is a stateful bean which works as a "work dispatcher" service - it receives events (on some scheduled time) and invokes stateless beans method passing appropriate arguments - those stateless beans do the whole job. My question is: how to obtain references to stateless beans (workers) in work dispatcher (executive) in a way that guarantee that stateless beans will be pooled (their state and number are managed by server, it is not just a single instance)?

       

      I know, that if I obtain a reference by JNDI to the bean, then I've got proxy object, but behind it, actually might be 10 stateless beans doing its work.

      But what if I am on the same virtual machine? Should I use @EJB annotation or maybe ordinary constructor?

       

      Thanks in advance,

      Piotr

        • 1. Re: Create stateless bean from stateful bean
          jaikiran

          I'm not quite sure I completely understand the question.

           

          piotrekde wrote:

           


           

          I know, that if I obtain a reference by JNDI to the bean, then I've got proxy object, but behind it, actually might be 10 stateless beans doing its work.

          Yes, you get a proxy and then when a method is invoked on that proxy, typically an instance of a SLSB is picked up from pool and the method is invoked on that instance.

           

          piotrekde wrote:

           


          But what if I am on the same virtual machine?


           

          You mean same JVM? I would say it doesn't make any difference, but I haven't yet understood the question, so I might be missing something.

           

          piotrekde wrote:

           

          Should I use @EJB annotation or maybe ordinary constructor?

           

          Never instantiate EJBs (or any server managed components) via the constructor invocation. Doing so will strip off all the server provided services off those components (for example, the instances will no longer be having any transaction or security semantics).