Professional Documents
Culture Documents
Java How To Program, 5/e Test Item File 1 of 3
Java How To Program, 5/e Test Item File 1 of 3
Chapter 16
Section 16.1
16.1 Q1: When dynamically allocated memory is not reclaimed, this can result in a serious error called a
__________ that can eventually exhaust the supply of free memory.
a.Memory leak.
b.Memory death.
c.Garbage error.
d.Collector error.
ANS: a. Memory leak.
16.1 Q2: With timeslicing, each thread is given a limited amount of time, called a __________, to execute on a
processor.
a.Quantum.
b.Processor burst.
c.Time allocation.
d.Scheduling interval.
ANS: a. Quantum.
Section 16.2
16.2 Q1: A new thread begins its life cycle by transitioning to the __________ state.
a.Ready.
b.Sleeping.
c.Running.
d.Born.
ANS: d. Born.
16.2 Q2: The thread remains in the Born state until the program calls Thread method __________, which
transitions the thread to the Ready state.
a.interrupt.
b.start.
c.run.
d.notify.
ANS: b. start.
16.2 Q3: A __________ thread becomes ready when the I/O it is waiting for completes.
a. blocked.
b. dead.
c. waiting.
d. sleeping.
ANS: a. blocked.
Section 16.3
Section 16.4
© Copyright 2003 by Deitel & Associates, Inc. and Prentice Hall. All Rights Reserved.
Java How to Program, 5/e Test Item File 2 of 3
None
Section 16.5
16.5 Q1: Only one __________ statement may be active on an object at once.
a.synchronized.
b.ordered.
c.exclusive.
d.thread.
ANS: a. synchronized.
16.5 Q2: If a thread calls __________, then every thread waiting for the object becomes eligible to reenter the
monitor.
a.notifyEach.
b.notifyAll.
c.notify.
d.notifyMethods.
ANS: b. notifyAll.
Section 16.6
16.6 Q1: In a producer/consumer relationship, when a consumer finds the buffer empty or finds that the previous
data has already been read, the consumer should call __________.
a.synchronized.
b.notify.
c.sleep.
d.wait.
ANS: d. wait.
Section 16.7
16.7 Q1: A __________ variable might typically be used to cause a producer to wait if shared memory cannot
currently be written.
a.Constant.
b.Constructor.
c.Concurrent.
d.Condition.
ANS: d. Condition.
16.7 Q2: In a producer/consumer relationship with a single cell of shared memory, which of the following is true?
a.The consumer must run first.
b.The producer must run first.
c.The producer must run first or the consumer will have to wait.
d.The consumer must run first or the producer will have to wait.
ANS: c. The producer must run first or the consumer will have to wait.
16.7 Q3: When a __________ method is running in an object, the object is locked so no other such method can run
in that object at the same time.
a.synchronized.
b.shared.
c.thread.
d.writeable.
ANS: a. synchronized.
Section 16.8
16.8 Q1: Which one of the following statements is true with regard to a producer/consumer relationship with one
producer and one consumer?
a.A producer can never produce faster than the consumer is consuming.
© Copyright 2003 by Deitel & Associates, Inc. and Prentice Hall. All Rights Reserved.
Java How to Program, 5/e Test Item File 3 of 3
b.A consumer can never consume faster than the producer is producing.
c.A producer can produce more items than a consumer consumes.
d.A consumer can consume more items than a producer produces.
ANS: c. A producer can produce more items than a consumer consumes.
16.8 Q2: Which of the following is true for a correct producer/consumer relationship with one producer, one
consumer, and a 5-cell circular buffer?
a.The producer can produce when all cells are full.
b.The consumer can consume when all cells are full.
c.The producer must run first.
d.The consumer can consume when all cells are empty.
ANS: b. The consumer can consume when all cells are full.
Section 16.9
16.9 Q1: Which of the following statements about daemon threads is false?
a.Daemon threads run in the background.
b.Daemon threads run for the benefit of other threads.
c.The garbage collector is a daemon thread.
d.Daemon threads run at a higher priority than "conventional" user threads.
ANS: d. Daemon threads run at a higher priority than "conventional" user threads.
16.9 Q2: We designate a thread as a daemon with the method call __________.
a.setDaemon();
b.createDaemon(true);
c.setDaemon(true);
d.convertTodaemon(true);
ANS: c. setDaemon(true);
Section 16.10
16.10 Q2: If we want multithreading supported in a class that is already derived from a class other than Thread, we
must implement the __________ interface in that class.
a.Thread.
b.Executable.
c.Multithreading.
d.Runnable.
ANS: d. Runnable.
© Copyright 2003 by Deitel & Associates, Inc. and Prentice Hall. All Rights Reserved.