02152  Concurrent Systems - Mini Lab 1: Java Threads
Technical University of Denmark DTU
02152 Concurrent Systems        Fall 2008
Mini Lab 1: Java Threads
Home Plan Material  

Purpose

To get the first experience with concurrent Java threads.

Prerequisites

This lab requires that you have installed Java Developoment Kit (JDK) (any version above 1.1 will do). It may also be carried out in the data bars.

See the note about processes and threads [Proc 4] for a description of threads in Java.

Instructions

  1. Fetch this Java program.
  2. Compile and run the program.
  3. Modify the program such that the class P is declared to extend the Thread class. What is the effect?
  4. Further modify the program such that the three processes P1, P2 and P3 are executed concurrently.

    You should make sure that the main thread (``Uncle Donald'') waits for the nephews to stop shouting [hint: use join()].

  5. Try to use the other method of thread instantiation (objects implementing Runnable passed to Thread objects).
  6. What happens if the call of Thead.sleep is commented out. Explain the result.
  7. Try to increase the number of iterations of each nephew (so that it takes several seconds to finish) and see if it makes any difference.

    You may try to move the mouse or activate some other program while the Java-program is running. Does it have any impact?

    Explain your observations.

  8. (Optional) Try to let each nephew calculate part of a problem and let Donald collect the results.

Enjoy!

Hans Henrik Løvengreen, Sep 4, 2008