问题
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