java - spring 集成 channel 是单线程的吗?

标签 java multithreading spring spring-integration

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

如果我在 spring 集成中有一个 rest(http) 服务作为入站 channel 会发生什么。每个请求是否仍然被并行处理,或者请求将被放入队列中......并且它更像是单线程

最佳答案

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

来自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.


编辑

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

关于java - spring 集成 channel 是单线程的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17875236/

相关文章:

java - 请建议一个基本的例子

Spring Data Rest Secure HATEOAS 链接

java - JTA 与本地事务

python - 确保 Celery 中不同来源的任务顺序

java - 在私有(private) IP 地址上托管服务器

java - 无法使用 Eclipse 创建 MapReduce 项目

java - 接口(interface)类java中的静态工厂方法

multithreading - Matlab多线程函数

c - C中父进程退出时杀死子进程

java - 如何在android中晃动时调用谷歌地图?