13 Parallel processing
This chapter covers
- Camel’s threading model
- Configuring thread pools and thread profiles
- Using concurrency with EIPs
- Handling scalability with Camel
- Writing asynchronous Camel components
Concurrency is another word for multitasking, and we multitask all the time in our daily lives. We put the coffee on, and while it brews, we grab the tablet and glance at the morning news while we eagerly wait for the coffee to be ready. Computers are also capable of doing multiple tasks—you may have multiple tabs open in your web browser while your mail application is fetching new email, for example.
Juggling multiple tasks is also common in enterprise systems, such as when you’re processing incoming orders, handling invoices, and doing inventory management, and these demands only grow over time. With concurrency, you can achieve higher performance; by executing in parallel, you can get more work done in less time.
Camel processes multiple messages concurrently in Camel routes, and it uses the concurrency features from Java, so we’ll first discuss how concurrency works in Java before moving on to how thread pools work and how you define and use them in Camel. The thread pool is the mechanism in Java that orchestrates multiple tasks. After we’ve discussed thread pools, we’ll move on to using concurrency with the EIPs.