Customizing a name of a thread in camel

天涯浪子 提交于 2020-01-16 00:50:09

问题


How do I customise a thread name of a particular component in Apache Camel?


回答1:


See http://camel.apache.org/threading-model.html:

<camelContext xmlns="http://camel.apache.org/schema/spring" threadNamePattern="Riding the thread #counter#">
  <route>
    <from uri="seda:start"/>
    <to uri="log:result"/>
    <to uri="mock:result"/>
  </route>
</camelContext>



回答2:


Thanks for your reply peter.I want to know how do i customise a thread name for particular component? For Ex:

<camelContext threadNamePattern="Riding the thread "counter#">
<threadPoolProfile id="fooProfile" poolSize="20" maxPoolSize="50" maxQueueSize="-1"/>
<route>
<multicast strategyRef="myStrategy" executorServiceRef="fooProfile">
</multicast>
<route>
</camelContext>

In the above code,the multicast uses fooprofile threadpool for multithreading and it is naming the threads as (assume) Riding the thread23,but it is not making sense,I am not sure about which thread is running for which component,I want to know customise a thread name for particular component For Ex:- Riding the thread23 for multicast DYnamically Is there a option to name a thread from components like multicast,splitter? Pls put your thoughts




回答3:


With an ExecutorService you have the possibility to define a ThreadFactory where you may set the desired thread name. Using Java DSL this could be done as follows:

ThreadFactory threadFactory = new ThreadFactory() {
    @Override
    public Thread newThread(final Runnable r) {
        Thread thread = new Thread(r);
        thread.setName("My Thread Name");
        return thread;
    }
};
ExecutorService exe = Executors.newFixedThreadPool(3, threadFactory);
from("direct:start")
    .threads()
    .executorService(exe)
    .log("${body}");


来源:https://stackoverflow.com/questions/26843327/customizing-a-name-of-a-thread-in-camel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!