In this chapter, we will discuss the ways to increase Java application performance by using the 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 the shared resource.
The following topics will be covered in this chapter:
- Thread vs process
- User thread vs daemon
- Extending class Thread
- Implementing interface Runnable
- Extending Thread vs implementing Runnable
- Using pool of threads
- Getting results from a thread
- Parallel vs concurrent processing
- Concurrent modification of the same resource