Skip to content

Module 11 Mastery Check

wolvesled edited this page Sep 20, 2013 · 1 revision
  1. Why does Java's multithreading capability enable you to write more efficient programs? Answer: It enables you to use cpu time more efficiently by multiple parallelable threads of task.
  2. Multithreading is supported by the _________ class and the __________ interface. Answer: Thread, Runnable
  3. When creating a runnable object, why might you want to extend Thread rather than implement Runnable? Answer: when adding more functionality to Thread.
  4. Show how to use join() to wait for a thread object called MyThrd to end. Answer: MyThrd.join();
  5. Show how to set a thread called MyThrd to three levels above normal priority. Answer: MyThrd.setPriority(Thread.NORM_PRIORITY + 3);
  6. What is the effect of adding the synchronized keyword to a method? Answer: allow object monitor to lock for only one thread accessing it at a time.
  7. The wait() and notify() methods are used to perform _____________________. Answer: thread communication to coordinate.
  8. Change the TickTock class so that it actually keeps time. That is, have each tick take one half second, and each tock take one half second. Thus, each tick-tock will take one second. (Don't worry about the time it takes to switch tasks, etc.) Answer: add sleep(500);
  9. Why can't you use suspend(), resume(), and stop() for new programs? Answer: it was deprecated because it may cause deadlock in multithreading programs.
  10. What method defined by Thread obtains the name of a thread? Answer: use getName() method.
  11. What does isAlive() return? Answer: boolean value whether the thread is running.
  12. On your own, try adding synchronization to the Queue class developed in previous modules so that it is safe for multithreaded use. Answer: add synchronized modifier to the methods those may change the Queue object.

Clone this wiki locally