Chapter 8: Multithreading and Concurrent Processing
In this chapter, we will discuss ways to increase Java application performance by using workers (threads) that process data concurrently. We will explain the concept of Java threads and demonstrate their usage. We will also talk about the difference between parallel and concurrent processing and how to avoid unpredictable results caused by the concurrent modification of a shared resource.
After finishing this chapter, you will be able to write code for multithreaded processing—creating and executing threads and using a pool of threads in parallel and concurrent cases.
The following topics will be covered in this chapter:
- Thread versus process
- User thread versus daemon
- Extending the
Thread
class - Implementing the
Runnable
interface - Extending
Thread
versus implementingRunnable
- Using a pool of threads
- Getting results from a thread
- Parallel versus concurrent processing
- Concurrent modification...