消息传递(例如JMS)何时是多线程的替代方案? [英] When is messaging (e.g. JMS) an alternative for multithreading?

查看:148
本文介绍了消息传递(例如JMS)何时是多线程的替代方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个数据处理应用程序上工作,通过在消息驱动bean(MDB)的多个实例监听的消息队列上放置几个工作单元来实现并发。除了以这种方式实现并发之外,我们没有任何具体的理由使用消息传递基础架构和MDB。

I work on a data processing application in which concurrency is achieved by putting several units of work on a message queue that multiple instances of a message driven bean (MDB) listen to. Other then achieving concurrency in this manner, we do not have any specific reason to use the messaging infrastructure and MDBs.

这让我想到为什么同样不可能使用多个线程实现。

This led me to think why the same could not have been achieved using multiple threads.

所以我的问题是,在什么情况下异步消息传递(例如JMS)可以用作替代mutithreading作为实现并发的手段?使用一种方法比另一种方法有什么优点/缺点。

So my question is, in what situations can asynchronous messaging (e.g. JMS) be used as an alternative to mutithreading as a means to achieve concurrency ? What are some advantages/disadvantages of using one approach over another.

推荐答案

它不能用作多线程的替代方法,它是实现多线程的一种方式。这里有三种基本类型的解决方案:

It can't be used as an alternative to multithreading, it is a way of of implementing multithreading. There are three basic kinds of solutions here:


  1. 你负责队列的两端;

  2. 您负责发送数据;或

  3. 您有责任接收数据。

接收数据是这里的踢球者,因为有没有某种形式的多线程/多处理,真的没办法做到这一点,否则你一次只能处理一个请求。在没有多线程的情况下发送数据更加可行,但是你只是将处理这些消息的责任推到了外部系统。所以它不是多线程的替代品。

Receiving data is the kicker here because there's really no way of doing that without some form of multithreading/multiprocessing otherwise you'll only be processing one request at a time. Sending data without multithreading is much more viable but there you're only really pushing the responsibility for dealing with those messages to an external system. So it's not an alternative to multithreading.

在你使用消息驱动bean的情况下,容器正在为你创建和管理线程,所以它不是多线程的替代品,你'只是简单地使用其他人的实现。

In your case with message driven beans, the container is creating and managing threads for you so it's not an alternative to multithreading, you're simply using someone else's implementation.

这篇关于消息传递(例如JMS)何时是多线程的替代方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆