02158  Concurrent Programming - Mini Lab 1: Java Threads
Technical University of Denmark DTU
02158 Concurrent Programming        Fall 2024
Mini Lab 1: Java Threads
Home Plan Material  

Purpose

To get a first experience with concurrent Java threads.

Prerequisites

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. Comment out the call of Thead.sleep and run the program several times.

    Are the execution patterns different from before? If so, try to explain why.

Enjoy!

Hans Henrik Løvengreen, Sep 6, 2024