java 骆驼是否为每条路线创建一个线程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12149557/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 07:47:26  来源:igfitidea点击:

Does camel create a thread for each route

javaapache-camel

提问by techuser soma

Recently i have started using camel and i see that it potentially addresses a lot of my integration layer needs.

最近我开始使用骆驼,我发现它可能满足我的很多集成层需求。

I have created a java client application (not running in any container) where i defined two routes:

我创建了一个 java 客户端应用程序(不在任何容器中运行),我在其中定义了两条路由:

route1: move a file from an incoming folder1 to folder2

route1:将文件从传入的文件夹 1 移动到文件夹 2

route2: move file content from folderx to mq queue.

route2:将文件内容从 folderx 移动到 mq 队列。

I start my application and these routes are doing their job polling those folders and routing messages accordingly.

我启动我的应用程序,这些路由正在轮询这些文件夹并相应地路由消息。

Can anyone explain me how the routes work. Does camel(context) create a thread for each route. What exactly happens?

谁能解释一下这些路线是如何工作的。骆驼(上下文)是否为每条路线创建一个线程。究竟会发生什么?

Note: I could not find a straightforward notes on this on the camel site.

注意:我在骆驼网站上找不到关于此的简单说明。

回答by Claus Ibsen

It depends on the components you use in the routes, how many threads are being created and used.

这取决于您在路由中使用的组件、正在创建和使用的线程数。

As well as some EIPs in Camel supports multiple threads (thread pools) and thus can be configured to use N number of threads.

以及 Camel 中的一些 EIP 支持多线程(线程池),因此可以配置为使用 N 个线程。

In your example its the file component, and it uses a single thread. As you have 2 routes, you will then use 2 threads. Some components also allows to configure their threading (eg thread pools). For example recently we added support for that for the file component in Camel 2.10 (see the scheduledExecutorService option at http://camel.apache.org/file2)

在您的示例中,它是文件组件,它使用单个线程。由于您有 2 条路线,因此您将使用 2 个线程。一些组件还允许配置它们的线程(例如线程池)。例如,最近我们在 Camel 2.10 中添加了对文件组件的支持(参见http://camel.apache.org/file2 上的 scheduleExecutorService 选项)

There is some notes here about Camel threading model http://camel.apache.org/threading-model.html

这里有一些关于 Camel 线程模型的注释 http://camel.apache.org/threading-model.html