Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

camel thread pooling query

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.

  1. why new threads are not getting created in pool ?
  2. Why new files are not getting picked ?
  3. How to resolve this issue ?
like image 371
Gnana Avatar asked Jul 31 '16 16:07

Gnana


1 Answers

As you have set poolsize as 1 , only one thread will be used to process.

Threads are created as follows

  1. If thread pool is smaller than the poolSize, a new thread is created to process.

  2. If jobs are less than maxQueueSize, then job is placed on the queue to wait for a free thread.

  3. 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

like image 65
ravthiru Avatar answered Oct 14 '22 00:10

ravthiru