1. For the following program, explain the interesting elements related to threads.

You may experiment with the program using the attached source code: TaskThreadDemo source code

1 public class TaskThreadDemo {
2 public static void main (String args []) {
3 String [] sa = {"a", "X", "+", "."};
4 for (String s: sa) {
5 Runnable ps = new PrintChar (s, 200);
6 Thread ts = new Thread (ps, s);
7 ts.start ();
8 } // end for each character
9 } // end main
10 } // end class TaskThreadDemo
11
12 class PrintChar implements Runnable {
13 String ch;
14 int times;
15
16 public PrintChar (String c, int n) {
17 ch = c;
18 times = n;
19 } // end constructor
20
21 public void run () {
22 for (int i = 0; i < times; i++) {
23 System.out.print (ch);
24 } // end for loop
25 } // end method run
26 } // end class PrintChar

2. What is changed if the method called on line 7, start(), is replaced with run()? Explain (of course).

3. What is changed if the method Thread.yield() is added between lines 23 and 24? Explain.

4. List and explain the threads running in your Sorcerer's Cave program as reported by jconsole. Note that you can name the threads created in the program, as is done on line 6 in Problem 1 above, which can make this discussion a lot easier to follow.

5. Explain how the java.util.concurrent.Semaphore class can be used in the Sorcerer's Cave program, final project, to coordinate the requirements of the various jobs.

6. Among object-oriented languages, one feature that varies considerably is whether the language allows multiple inheritance. C++ does but Ada does not. Java takes a middle ground approach of allowing multiple inheritance of interfaces but not classes. Using a C++ example, illustrate some of the complexities that multiple inheritance introduces. How does C++ deal with them? Why does Java's middle ground approach offer some of the benefits of multiple inheritance while avoids its problems.

7.

(a) Give an example where an executor pool is appropriate.

(b) Why are some of the methods in the Thread class deprecated? Give a short explanation.

8. Choose any graph algorithm we have studied and find a real-world problem which might be solved using it. Describe the relationship between the real-world entities and the formal representation (What does vertices represent? What edges? Weights if it is the case.) and how the algorithm is applied. Discuss the efficiency and implementation related aspects.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.