[SDU Logo]   Dept. of Mathematics and Computer Science
University of Southern Denmark Phone/Email Directory | Maps

   
 DM519 - 2012
Home
Schedule
Weekly Notes

 

Weekly Note 1

Project

Part of passing the course is a mandatory project. This is composed of several weekly assignments and a final mini-project. You need to get a pass grade on these before attending the oral exam in June.

More details will follow soon.

Discussion Section, Wednesday April 11 at 12:15 in U26

For some of the following exercices, you may want to get more information about threads in Java, this can be found in the Java documentation.

  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. 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 Thread.sleep).
  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 Thread.sleep). 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)?
  6. The Fibonacci sequence is the series of numbers 0, 1, 1, 2, 3, 5, 8, ... Formally, it can be expressed as: f0 = 0, f1 = 1, and fn = fn-1 + fn-2. Write a multithreaded program that generates the Fibonacci sequence using Java. Given any n, the program creates a separate thread that generates the numbers, saving the resulting sequence in a shared variable (an array is probably the most convenient data structure). When the thread is done, the parent thread outputs the sequence.