Week 6

Format

The course is taught by Peter Schneider-Kamp. Lectures will be on Fridays 08:15-10:00 in U20 as well as in some weeks on Mondays 12:15-14:00 in differing rooms.

There are three sections of students: 1st year computer science (S7, S17) and other (S1). These sections will meet for both discussion sections and lab exercises taught by Christian Østergaard Lautrup Nørskov (S7), Mathias Wulff Svendsen (S17), and Jakob Lykke Andersen (S1).

Lecture Monday (03.02.2014)

The first lecture will introduce processes and how to model them using labelled transition systems. Then we will learn two different ways in which thread can be used in Java.

Reading

Chapter 1 and 2

Lecture Friday (07.02.2013)

The second lecture will introduce concurrent processes. We will learn both how to model them using labelled transition systems and how to implement them in Java.

Reading

Chapter 3

Study Groups

Prepare by looking the information about threads in Java here.

1) MyThread:
Write a program in Java, MyThread, that starts a thread (as a sub-class of the Thread class) which outputs "Running ..." every second (using the Thread.sleep method).

2) MyNamedThread:
Modify the above program such that MyThread gets a String argument in its constructor. Let the main method start three instances of MyThread with different names.

3) MyRun:
Write a program in Java, MyRun, that starts a thread (as an implementation of the Runnable interface) which outputs "Running ..." every second (using the Thread.sleep method). Why is this often a preferable way of constructing threads?

4) MyRunInterrupt:
Modify the above program so that the main thread starts the thread specified above, sleeps for 5 seconds, and then stops it. How did you "stop" the other thread? Are there any other ways of stopping the thread (and why are some approaches not a good idea)?

5) MyRunInterrupt2:
Modify the above program so that the created thread makes some time-consuming computation, for instance:

for (int i=0; i<100000000; i++) {
    /* Waste time creating objects */
    Object o = new Object();
}

Note: you have to take care that your time-consuming computation does not get optimized away (hence the "pointless" creation of objects). How did you then stop this thread from the main thread? Are there any other ways of stopping the thread (and why are some approaches not a good idea)?

Lab

For the implementation tasks, you can find more information about threads in Java here.

1) Labelled Transition System Analyser (LTSA):
Try the LTSA available from the course book home page. You can find most of the examples in our text book, inside File | Examples. We will use the LSTA extensively in the coming weeks.

2) Do Exercises 2.1, 2.3, and 2.4.

3) Do Exercises 3.2 and 3.4.

4) Present the results of Tasks 1-5 from the study group work.

Design by 1234.info | Modified by Peter Schneider-Kamp | CSS 2.0