|
|
Lab 3 -- Java Threads
Thread creation and execution
- Build and implement the
SimpleThread example from the lecture
slides for week 3. Make sure that you understand the program. Modify
the example so that the SimpleThread
class implements Runnable rather than
extends Thread. Get the program working
in this way so that its behaviour is similar to the original
program.
- Work through the first four sections of the IBM tutorial at http://cgweb1.unn.ac.uk/SubjectAreaResources/CM637/j-threads/j-threads/
(The original tutorial material can be accessed from IBM at http://www-128.ibm.com/developerworks/edu/j-dw-javathread-i.html)
In particular, you should do the following tasks:
- In the third section, 'A Thread's Life', build and run the
example TwoThreads and observe the
results. Make sure that you understand the program. Modify the program
so that there is only one thread class which takes its two output
characters as parameters. This class should not extend Thread but
rather should implement Runnable. Get the program working in this way
so that its behaviour is similar to the original program.
- In the same section, build and run the example
TenThreads. You will need to provide
your own implementation of
getBigHairyMatrix(). Make sure that you
understand the
program. Modify the program so that it uses
twenty threads instead of ten threads. Again, modify the
program to use the runnable object approach rather than the
thread extension approach. Get the program working in this
way so that its behaviour is similar to the original program.
- Work through sections 1, 3 and 4 of the Sun tutorial at http://java.sun.com/docs/books/tutorial/essential/threads/. Build
and implement the examples. Make sure that you understand them. Make
small modifications to each program to test your understanding.
|