From the course: Java Practice: Exception Handling

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Solution: Multiple Threads

Solution: Multiple Threads - Java Tutorial

From the course: Java Practice: Exception Handling

Solution: Multiple Threads

- [Instructor] Here is my solution to the challenge. And you may have had a different one yourself, and that's great. I'm going to start by hiding my test code because we can't change it anyway. And I also want to talk about why I added this challenge. This is because of a problem that I ran into during Java development. When working in a multi-threaded environment, especially when using something like an executor service, sometimes exceptions are not caught. So if I were to have a catch statement to catch all the exceptions here, it wouldn't catch the ones that are thrown even though every single task is throwing an exception. So when you're working in a multi-threaded environment, you need to be pragmatic about handling your exceptions so that you find them when they occur in your code. To do that, you can use something called a future, which holds the result of an asynchronous task. So that would look like this. Future,…

Contents