Java Reference
In-Depth Information
Answers to Review Questions
1.
public void run()
2.
True. A process cannot exist without at least one non-daemon thread.
3.
True. That is the definition of a daemon thread, that it does not keep the process alive.
4.
c is not correct. The underlying platform plays a large role in the way your threads will
actually behave at run time. Running a multithreaded application on different plat-
forms can have quite different results.
5.
True. Threads do not run until the start() method of the Thread class is invoked.
6.
False. The number of threads running depends on the number of CPUs available.
7.
You can do the following: (1) write a class that implements Runnable and wrap it in a
Thread object, (2) write a class that extends Thread, or (3) extend TimerTask and
schedule it with a Timer object.
8.
a is not true because many platforms give lower-priority threads a chance to run to
avoid higher-priority threads hogging the CPU. b is not true because B will yield only
to threads of priority 10. c is true because calling sleep() causes B to block, which
makes A the only runnable thread, meaning that A will get scheduled. d is false
because time slicing does not affect priority. e is false because deadlock has nothing to
do with priorities. f is true because that is how the join() method works.
9.
a is true because the delay is 0. b is false because this is fixed-delay scheduling.
Instead, c is true. d is false because this task has a period of 10 seconds. e is false.
10.
a is true because the delay is 0. b is false because this is fixed-rate scheduling. Instead,
c is true. Both d and e are true.
11.
False. The statement basically makes no sense.
12.
True. That is the effect of the synchronized keyword on methods.
13.
True.
14.
True. To wake up all waiting threads, use notifyAll() instead of notify().
15.
True. Otherwise, another thread would be unable to invoke notify(). Recall that a
thread must own the object's lock to invoke wait() or notify() on the object.
Search WWH ::




Custom Search