Is it legal to inject a @Stateful into an MDB?

大憨熊 提交于 2019-12-23 12:19:50

问题


Is it legal to inject a @Stateful into an MDB?

@Stateful
public class InteruptBean implements Interrupt {
    ....
}

@MessageDriven(...)
public class EchoTrigger implements MessageListener {
    @EJB Interrupt interrupt;

    ....
}

Or better phrased: Can I use a stateful EJB to pass state around in an asynchronous Event Driven Architecture?


回答1:


Yes, it's "legal", but it's nonsensical. MDBs instances are pooled like SLSBs. The MDB will become non-functional after the SFSB times out.

It might work to explicitly create the SFSB at some point, and then pass a reference to the SFSB in the messages being sent to drive the MDB.




回答2:


Yes it does not make sense. Because stateful session beans are meant for processing multiple requests from same client so that they have client-actions oriented processing. In this case MDB will be beans clients. MDB supports single request model. A request comes to MDB (in form of message) and it is processed. So both types of beans don't match in processing model.



来源:https://stackoverflow.com/questions/6527552/is-it-legal-to-inject-a-stateful-into-an-mdb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!