首页 > 解决方案 > 停止+中断现有路线

问题描述

我有一条正在等待锁的骆驼路线。让我们模拟如下:

context.addRoutes(new RouteBuilder() {
    @Override
    public void configure() throws Exception {
        from("timer://foo?period=100")
                .to("direct:bar");
        from("direct:bar")
                .routeId("test")
                .to("log:receive")
                .process(new Processor() {
                    @Override
                    public void process(final Exchange exchange) throws Exception {
                        System.out.println("sleeping indefinitely");
                        try {
                            Thread.sleep(Long.MAX_VALUE);
                        } catch (final InterruptedException exception) {
                            exception.printStackTrace();
                        }
                        System.out.println("not sleeping indefinitely");
                    }
                });
    }
});

在某个时间点,我想尽快停止这test条路线。有没有办法在中断当前处理这条路线的线程时停止这条路线?我尝试stopRoute如下,但这似乎并没有中断线程。

context.getRouteController().stopRoute("test", 1, TimeUnit.NANOSECONDS);

我正在使用 Camel 版本 3.4.x。

标签: apache-cameljava-threadsapache-camel-3

解决方案


推荐阅读