Can i write a stateful sessionbean implement a messagelistener


EJB programming & troubleshooting: Can i write a stateful sessionbean implement a messagelistener

  1. my design requires me to write a stateful session bean which will implement jms message listener. Teh stateful bean will bind to a queue and listen for messages. Is it correct to design so and is it implmentable?
  2. Hi,
       You can implement stateful session bean to be synchronous message listener - my understanding.
  3. Hi!

    From a quick look in the specification, I cannot find something saying "you should not" on this point.

    However, to me it seems a bit strange and I havn't seen anything like this before. You should be aware for the concept of durable/non-durable when registring the message listener.

    Also note that you may end up in a situation when two threads execure your EJB at the same time: Your normal client thread and the thread started by an incoming message.

  4. Although java does not prevent you to have a session bean implementing messageLiListener, the J2EE does not allow multi threading in EJB. and the idea of EJB blocking waiting a message to arrive is not feasible. Look at it this way: EJBs are not guaranteed to exist between method calls depending on the container. If the been is not called for a while it might be passivated.

    Read this Article: