Execution threads are the core of concurrent applications. When you implement a concurrent application, no matter the language, you have to create different execution threads that run in parallel in a non-deterministic order unless you use a synchronization element (such as a semaphore). In Java you can create execution threads in two ways:
- Extending the Thread class
- Implementing the Runnable interface
In this chapter, you will learn how to use these elements to implement concurrent applications in Java. We will cover the following topics:
- Threads in Java: characteristics and states
- The Thread class and the Runnable interface
- First example: matrix multiplication
- Second example: file search