As we explain in Chapter 2, Working with Basic Elements - Threads and Runnables, the basic mechanism to implement a concurrent application in Java is:
- A class that implements theRunnable interface: This is the code you want to implement in a concurrent way
- An instance of theThread class: This is the thread that is going to execute the code in a concurrent way
With this approach, you're responsible for creating and manning the thread objects and implementing the mechanisms of synchronization between the threads. However, it can create some problems, especially with those applications with a lot of concurrent tasks. If you create too many threads, you can degrade the performance of your application or even hang the entire system.
Java version 5 included the Executor framework to solve these problems and provide an efficient solution that is easier to use for programmers than the traditional concurrency mechanisms.
In this chapter, we will introduce the basic characteristics...