The purpose of this laboratory is to:
- Introduce you to the multithreading features of Java.
- Study and run a simple program with two threads.
- Modify the given program for doing more sophisticated tasks and learn other features of multithreading.
Note: you may find it useful to look at the ofthe , which includessimilar examples and exercises.
Multithreading in Java
You have already briefly seen in the lectures what is meant bymultithreading. We will concentrate mainly on the multithreading andsynchronization features of Java in these laboratories. To remind youagain the essential features of multithreading:
- multithreading is the simultaneous execution of multiple threads of control within the same program or process. By simultaneous we mean that if there is a single CPU, it switches back and forth between the threads.
- All the threads within the same process share a common address space.
Java provides two approaches for creating and managing multiple threads. In this lab, we will see the first approach and study it carefully. Then, we will see the limitations of this approach and study a slightly more general and powerful approach.