I am working on camel thread pooling and using pooling size and max pooling size. my understanding is each request will be handled by one thread and if request > pool size, new one thread will be created in pool using max pool size. To ensure my understanding I did below POC.
public class FileMoverRoute extends SpringRouteBuilder {
@Override
public void configure() throws Exception {
CamelContext context = getContext();
ExecutorService executorService = new ThreadPoolBuilder(context)
.poolSize(1).maxPoolSize(10).maxQueueSize(100).build("CustomThreadPool");
from("file://C:/from").log("Received ${body}:${threadName}").threads().executorService(executorService)
.log("Processing ${body}:${threadName}").process(new FileProcessor()).to("file://C:/to");
}
}
public class FileProcessor implements Processor{
public void process(Exchange exc) throws Exception {
Map<String, Object> headerMap = exc.getIn().getHeaders();
System.out.println(" sleep for minute");
TimeUnit.MINUTES.sleep(1);
System.out.println(" woke up"+headerMap);
}
}
I gave 1 min sleep in File processor. If I put 1 file(1.txt) inside from folder I could see received & Processing log in console. If put next 2 files(2.txt,3.txt) files inside from folder. I could see received log for 2 files not processing log. since my max pool size is 10, camel should increase threads and pick the file.
As you have set poolsize as 1 , only one thread will be used to process.
Threads are created as follows
If thread pool is smaller than the poolSize, a new thread is created to process.
If jobs are less than maxQueueSize, then job is placed on the queue to wait for a free thread.
If queue is full and the thread pool has less than maxPoolSize threads instantiated, a new thread is created to process the Job.
You can test by yourself by reducing the QueueSize
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With