gpt4 book ai didi

java - Camel 路线执行优先级

转载 作者:行者123 更新时间:2023-11-30 08:19:55 26 4
gpt4 key购买 nike

我想了解 Camel 是否能够在同一进程中优先执行一条路由而不是另一条路由。

例如,我们有:

from("cxfrs://restendpoint").routeId("HIGH").log("high priority");

from("file://filestore").routeId("LOW").log("low priority");

我希望 HIGH 路线不会被 LOW 路线减速。因此,当 LOW 路由正在处理一个巨大的文件并且一个 rest 调用到达 HIGH 路由时,我希望 CPU 给 HIGH 路由更多的时间。

我正在考虑通过将路由拆分为 2 个应用程序并使用 Linux 进程优先级为 HIGH 路由分配更多时间来做到这一点。

有没有办法用 Camel 做到这一点?例如,可以玩线程优先级的东西?

谢谢你的帮助

最佳答案

看看Apache Camel/ActiveMQ priority route (初始情况不同,但解决方案也适用于您的用例):

  • 使用 JMS 并确定队列的优先级
  • 使用 SEDA 阻塞队列,同样描述 here
  • 使用重新排序器

编辑:

作为附加选项,使用带有自定义 ThreadFactoryExecutorService 并设置线程优先级,例如:

ThreadFactory threadFactory = new ThreadFactory() {
@Override
public Thread newThread(final Runnable r) {
Thread thread = new Thread(r);
thread.setPriority(Thread.MIN_PRIORITY);
return thread;
}
};

ExecutorService exe = Executors.newFixedThreadPool(3, threadFactory);

from("direct:slow")
.threads()
.executorService(exe)
...

可以找到一篇关于 Java 线程优先级的好文章 here .

关于java - Camel 路线执行优先级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26470638/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com