消息队列 VS 线程池
消息队列和线程池有什么区别?
What the difference between message queues and thread pools?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
消息队列和线程池有什么区别?
What the difference between message queues and thread pools?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
消息队列 用于(异步)进程间通信,而 线程池用于在一组线程上运行多个任务。我想不出一种合理的方法来比较它们……它们在很多方面都有根本上的不同。
Message Queue is used for (asynchronous) inter-process communication while a Thread Pool is used to run multiple tasks on a set of threads. I can't think of a reasonable way to compare them... they're fundamentally different from each-other in so many ways.
真正的问题是两者之间是否有相似之处。消息队列是一种数据结构,用于保存消息(从发送消息到接收者检索消息并对其执行操作)。
线程池是执行某种处理的线程池。线程池通常会附加某种线程安全队列,以允许您对要完成的作业进行排队。这通常被称为“任务队列”而不是消息队列,尽管它通常包含某种描述需要完成的任务的消息。
The real question would be whether there's any similarity between the two. A message queue is a data structure for holding messages from the time they're sent until the time the receiver retrieves and acts on them.
A thread pool is a pool of threads that do some sort of processing. A thread pool will normally have some sort of thread-safe queue attached to allow you to queue up jobs to be done. This would more often be called something like a "task queue" than a message queue, though it will normally contain some sort of messages that describe the tasks that need to be done.
消息队列
通常用于分布式系统,线程池
通常用于单机。顺便说一句,线程池内部使用阻塞队列。如果您使用消息队列
,您将花费更多时间来维护它。不要过度设计。当然,消息队列具有更复杂的功能,并且擅长解耦。
(ps:你可以看一下这个问题:为什么是消息队列使用多线程代替?)
message queue
usually used in distributed system,thread pool
often used in individual machine. btwthread pool
use blocking queue internally. if you usemessage queue
, you will cost more time to maintain it. Don't over-designed.Of course,
message queue
hava more complex features, and good at decoupling.(ps: u can look at the question:Why are message queues used insted of mulithreading? )