有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java是单线程的spring集成通道吗?

如果我有一个rest服务,我肯定每个请求都由一个单独的线程处理,线程可以并行运行

如果在spring集成中使用rest(http)服务作为入站通道,会发生什么。每个请求是否仍将被并行处理,或者请求将被放置在队列中。。。它将更像是单线程的


共 (1) 个答案

  1. # 1 楼答案

    普通通道(DirectChannel)使用与将某些内容放入通道的对象相同的执行线程(它们基本上是抽象方法调用的一种方式),因此它们是多线程的

    docs开始:

    In addition to being the simplest point-to-point channel option, one of its most important features is that it enables a single thread to perform the operations on "both sides" of the channel. For example, if a handler is subscribed to a DirectChannel, then sending a Message to that channel will trigger invocation of that handler's handleMessage(Message) method directly in the sender's thread, before the send() method invocation can return.


    编辑

    你的问题很有道理。在通道中设置队列元素时,spring会自动将其转换为QueueChannel(documentation),就我所知,一次只有一个线程能够从队列中使用。如果您想要“真正的”队列语义(几个生产者和消费者线程),可以使用ExecutorChannel