CamelContext.start () does not block

I want to run a simple Apache Camel example that copies files from one directory to another:

CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder() {

  public void configure () throws Exception {
    from("file://c:/fromdir/").to("file://c:/todir/");
  } 
});
context.start();

If I run this example using Apache Camel 2.0.0, the program will exit right after context.start();and does nothing. If I add Thread.sleep(30000);after launch CamelContext, the background threads do their job and the files are copied from the source to the destination directory within 30 seconds.

However, if I run the same code using Apache Camel 1.6.2, the method is start()blocked automatically, and I do not need to put the main thread to sleep to copy files. I did not find a hint that this behavior has changed from Camel 1.x to 2.x. Is this really intended behavior? Is it possible for the start () method to block execution in Camel 2.0.0?

thanks

+3
source share
2 answers

Yes, calling start () in the context of a camel should never block a thread. And this is the correct behavior of Camel 2.0.

MainSupport org.apache.camel.util , ctrl + c () CamelContext.

. , Main in camel- spring, MainSupport Camel XML spring.

+7

Thread.currentThread().join();

context.start();

+10

Source: https://habr.com/ru/post/1724741/


All Articles