In this exercise, you will become familiar with the concepts of multithreading by writing a multithreaded program.
The purpose of this lab is to create three threads and run them at the same time. While they are running, they will print out their names to the standart output stream. By observing what is printed, you can observe how the threads run and in what order.
Before you begin, make sure that you have changed directories to
cd ~/exercises/mod13_threads/exercise1/
Using a text editor, create the
Using a text editor, create the TestThreeThreads program. In the main method create three threads using the
On the command line, use the
On the command line, use the java command to run the test program. You should see output similar to this.
T3 - Moe
T2 - Curry
T1 - Larry
T1 - Larry
T3 - Moe
T2 - Curry
T1 - Larry
T3 - Moe
T2 - Curry
T1 - Larry
T3 - Moe
T2 - Curry
T1 - Larry
T3 - Moe
T2 - Curry
T1 - Larry
T3 - Moe
T2 - Curry
T1 - Larry
T3 - Moe
T2 - Curry
T1 - Larry
T3 - Moe
T2 - Curry
T1 - Larry
T3 - Moe
T2 - Curry
T1 - Larry
T3 - Moe
T2 - Curry
T1 - Larry
T3 - Moe
T2 - Curry
Run this program several times. Notice that you you may see different results of each execution.
Discussion - Can you explain the behavior of your program?