开发者

Message Queue VS Thread Pool

What the difference b开发者_如何学运维etween message queues and thread pools?


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.


message queue usually used in distributed system, thread pool often used in individual machine. btw thread pool use blocking queue internally. if you use message 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? )

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜