English 中文(简体)
CamelContext.start() doesn t 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 exits immediately after context.start(); and does nothing. If I add Thread.sleep(30000); after the starting of the CamelContext, the background threads do their work and files get copied from the source to the destination directory for 30 seconds.

However, if I run the same code using Apache Camel 1.6.2 the start() method blocks automatically and I don t need to put the main thread to sleep in order to get files copied. I haven t found a hint that this behavior changed from Camel 1.x to 2.x. Is this really the intended behavior? Is it possible to let the start() method block the execution in Camel 2.0.0?

Thanks

最佳回答

Yeah calling start() on camel context should never block the thread. And this correct behavior of Camel 2.0.

You can use the MainSupport class from org.apache.camel.util as a starting point to have blocked until you hit ctrl + c or call stop() on CamelContext.

See for example Main in camel-spring which extends MainSupport and is capable of loading Camel from a spring XML file.

问题回答

Or you can add

Thread.currentThread().join();

after context.start();





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签