Exercise : Using Multithreaded Programming ( Level 2 )

In this exercise, you will become familiar with the concepts of multithreading by writing a multithreaded program.

 

 

Task 1 - Creating the PrintMe Class

Using a text editor, create the PrintMe class that implements the Runnable interface. Create the run method to perform teh following actions 10 times. Print the name of the current thread and then sleep for 2 seconds.

  1. Declare the PrintMe class. This class must implement the Runnable interface.
  2. Crate the run method to loop the following 10 times. Print the name of the current thread and then sleep for 2 seconds.

 

 

Task 2 - Creating the TestThreeThreads Program

Using a text editor,  create the TestThreeThreads program. In the main method create three threads using the PrintMe runnable class. Give each thread a unique name using the setName  method. Start each thread.

  1. Declare the TestThreeThreads class.
  2. Crate the main method.

    1. Create three thread objects and pass an instance of the PrintName class each constructor.

    2. Give each thread a unique name using the setName method.

    3. Start each thread.

 

 

Task 3 - Compiling the TestThreeThreads Program

On the command line, use the javac command to compile the test program.

 

 

Task 4 - Running the TestThreeThreads Program

On the command line, use the java command to run the test program. You should see output similar to that shown in "Task 4 - Running the TestThreeThreads Program" on page Lab 13 - 3.