-
Notifications
You must be signed in to change notification settings - Fork 1
Module 11 Mastery Check
wolvesled edited this page Sep 20, 2013
·
1 revision
- 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.
- Multithreading is supported by the _________ class and the __________ interface. Answer: Thread, Runnable
- When creating a runnable object, why might you want to extend Thread rather than implement Runnable? Answer: when adding more functionality to Thread.
- Show how to use join() to wait for a thread object called MyThrd to end. Answer:
MyThrd.join(); - Show how to set a thread called MyThrd to three levels above normal priority. Answer:
MyThrd.setPriority(Thread.NORM_PRIORITY + 3); - 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.
- The wait() and notify() methods are used to perform _____________________. Answer: thread communication to coordinate.
- 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); - Why can't you use suspend(), resume(), and stop() for new programs? Answer: it was deprecated because it may cause deadlock in multithreading programs.
- What method defined by Thread obtains the name of a thread? Answer: use getName() method.
- What does isAlive() return? Answer: boolean value whether the thread is running.
- 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.