Java源码示例:org.apache.camel.builder.ThreadPoolBuilder
示例1
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
// create a thread pool builder
ThreadPoolBuilder builder = new ThreadPoolBuilder(context);
// use thread pool builder to create a custom thread pool
ExecutorService myPool = builder.poolSize(5).maxPoolSize(25).maxQueueSize(200).build("MyPool");
from("direct:start")
// use our custom pool in the threads DSL
.threads().executorService(myPool)
.to("log:cool")
.to("mock:result")
.end();
}
};
}
示例2
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
// create a custom thread pool
ExecutorService lowPool = new ThreadPoolBuilder(context)
.poolSize(1).maxPoolSize(5).build("LowPool");
// which we want the WireTap to use
from("direct:start")
.log("Incoming message ${body}")
.wireTap("direct:tap").executorService(lowPool)
.to("mock:result");
from("direct:tap")
.log("Tapped message ${body}")
.to("mock:tap");
}
};
}
示例3
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
// create a thread pool builder
ThreadPoolBuilder builder = new ThreadPoolBuilder(context);
// use thread pool builder to create a custom thread pool
ExecutorService myPool = builder.poolSize(5).maxPoolSize(25).maxQueueSize(200).build("MyPool");
from("direct:start")
// use our custom pool in the threads DSL
.threads().executorService(myPool)
.to("log:cool")
.to("mock:result")
.end();
}
};
}
示例4
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
// create a custom thread pool
ExecutorService lowPool = new ThreadPoolBuilder(context)
.poolSize(1).maxPoolSize(5).build("LowPool");
// which we want the WireTap to use
from("direct:start")
.log("Incoming message ${body}")
.wireTap("direct:tap").executorService(lowPool)
.to("mock:result");
from("direct:tap")
.log("Tapped message ${body}")
.to("mock:tap");
}
};
}
示例5
@Override
public void configure() throws Exception {
ThreadPoolBuilder builder = new ThreadPoolBuilder(getContext());
ExecutorService oneThreadOnly = builder.poolSize(1).maxPoolSize(1)
.maxQueueSize(100).build("JustMeDoingTheTapping");
from("direct:start")
.wireTap("direct:tapped").executorService(oneThreadOnly)
.to("mock:out");
from("direct:tapped")
.setHeader("threadName").simple("${threadName}")
.to("mock:tapped");
}
示例6
@Override
public void configure() throws Exception {
CamelContext context = getContext();
ExecutorService executorService = new ThreadPoolBuilder(context).poolSize(5).maxQueueSize(100).build("CustomThreadPool");
from("direct:in")
.log("Received ${body}:${threadName}")
.threads().executorService(executorService)
.log("Processing ${body}:${threadName}")
.transform(simple("${threadName}"))
.to("mock:out");
}