How to understand the “synchronous” and “asynchronouns” messaging in JMS?

前端 未结 4 1840
温柔的废话
温柔的废话 2020-12-24 02:18

After reading some document of JMS, I totally puzzled by the phrase synchronous and asynchronouns.

See this page: http://docs.oracle.com/cd

4条回答
  •  佛祖请我去吃肉
    2020-12-24 03:14

    If you understand it better like this, consumer.receive() uses a pull model: you read from a queue and are blocked waiting for this message until it comes, or some timeout has elapsed.

    Using a listener uses a push model: you register a listener and, when a message comes in, the listener is called, in a separate thread.

    Everything is done in a thread in Java, and the listener call is no exception. Whether the listener message handling prevents the processing of other messages in the queue depends on how many threads are dedicated to message processing. If you configure Spring to use a pool of 5 threads to process messages asynchronously, then 5 listeners will be able to process messages in parallel.

提交回复
热议问题