当前位置: 动力学知识库 > 问答 > 编程问答 >

Jms message listeners implement Runnable

问题描述:

For asynchronous JMS consumers, the standard way of designing the consumer is:

1.Create a MessageConsumer

2.Create a MessageListener & implement onMessage()

3.Register the listener with the consumer

Now, in some examples on the net, the MessageListener class is implemented as a Runnable. Is this a good practice? there are 2 scenarios which I am thinking of:

1. Standalone MessageConsumer

2.MessageConsumer running inside a J2EE server.

Any help is greatly appreciated.

网友答案:

If you're in a Java EE environment, using Runnable isn't bad - but managing your own threads usually is. There, you're far better off using an MDB and allowing the container to handle concurrent messages.

Outside of Java EE, having the listeners implement Runnable isn't a terrible idea - it's often not very necessary since the registration will take care of threading in most cases. I'd say not to worry about it unless you see an actual problem.

分享给朋友:
您可能感兴趣的文章:
随机阅读: