In a processor in a camel route I am retrieving data with a cursor and sending it to a route that sends it in batches to the database. The current ProducerTemplate sends the data in a synchronous manner.
ProducerTemplate template = exchange.getContext().createProducerTemplate();
do {
template.send(START_ROUTE_TO_DATABASE, exchange.copy());
} while new data is retrieved
When I make the process faster by making the call asynchronous template.asyncSend(START_ROUTE_TO_DATABASE, exchange.copy()); the app still runs, but it start consuming a lot of memory. I want to limit this memory use, by limiting the number of threads that get created when template.asyncSend() is called. What is the best way to limit the number of threads? Is there another way to limit memory use that I am overlooking?