From the course: Parallel and Concurrent Programming with Java 2
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Thread pool - Java Tutorial
From the course: Parallel and Concurrent Programming with Java 2
Thread pool
- After identifying the tasks in a program that can run asynchronously, one way to run those tasks in parallel is to create independent threads or processes for each of them. Preparing a basic salad requires us to chop lettuce and chop tomatoes. So Olivia and I will act as independent threads to execute those tasks in parallel on our two processors, the knives. - A salad with just lettuce and tomatoes is so boring. We need something more. What about cucumbers? - Sure. Chopping cucumbers is another task that can run asynchronously so we'll spawn another thread to handle that. Hey Barron. - Hey Barron. - We need onions too. What's up, Olivia? - What's up? - Another task, another thread. - And mushrooms. - Again, another thread. - And carrots, and celery, and peppers and an eggplant. - Whoa, whoa, whoa. It's getting crowded in here. We've got to lot of threads in the kitchen but only two processors to execute on. That means a lot of threads'll be standing around waiting their turn…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.