Deck 26: Multithreading

Full screen (f)
exit full mode
Question
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.
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.
Use Space or
up arrow
down arrow
to flip the card.
Question
When a thread obtains the monitor lock on an object,then determines that it cannot continue with its task on that object until some condition is satisfied,the thread can call Object method ________;this releases the monitor lock on the object,and transitions the thread waits to the waiting state.

A)waitForOtherThreads.
B)stop.
C)waitForCondition.
D)wait.
Question
Which of the following is not true of ExecutorService?

A)It is a subinterface of Executor.
B)It is an object that can be run in a separate thread.
C)It declares method shutdown.
D)It manages a group of threads.
Question
A new thread begins its life cycle by transitioning to the __________ state.

A)runnable.
B)waiting.
C)terminated.
D)new.
Question
This class is used to help implement mutual exclusion.

A)MutEx.
B)Condition.
C)Lock.
D)Signal.
Question
When a __________ method or block is running on an object,the object is locked so no other such method can run on that object at the same time.

A)synchronized.
B)shared.
C)thread.
D)writeable.
Question
The main method executes in the ________ thread of execution.

A)starting
B)main
C)local
D)None of the above.
Question
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.
Question
The BlockingQueue interface declares which two methods for blocked adding and blocked removing of elements from a circular buffer?

A)put and take.
B)add and remove.
C)push and pop.
D)place and get.
Question
The preferred means of creating multithreaded Java applications is by implementing the ________ interface.An object of a class that implements this interface represents a task to perform.

A)Thread.
B)Runner.
C)Runnable.
D)None of the above.
Question
The ArrayBlockingQueue method ________ returns the number of elements currently in the ArrayBlockingQueue?

A)size.
B)length.
C)getSize.
D)getLength.
Question
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.
Question
In a producer/consumer relationship,the ________ portion of an application generates data and stores it in a shared object,and the ________ portion of an application reads data from the shared object.

A)consumer,producer.
B)producer,consumer.
C)outputter,inputter.
D)None of the above.
Question
Interface ExecutorService provides the ________ method,which returns control to its caller either when all tasks executing in the ExecutorService complete or when the specified timeout elapses.

A)waitForTermination.
B)wait.
C)awaitTermination.
D)None of the above.
Question
Which of the following is true for a correct producer/consumer relationship with one producer,one consumer,and a 5-cell buffer?

A)The producer can produce when all cells are full.
B)The consumer can consume when all cells are full.
C)The consumer can consume when all cells are empty.
D)None of the above.
Question
When a thread executing a synchronized statement (or method)completes or satisfies the condition on which another thread may be waiting,it can call Object method ________ or ________ to allow a waiting thread or all waiting threads to transition to the runnable state again.

A)notifyThread,notifyAllThreads.
B)wakeUpThread,wakeUpAllThreads.
C)notify,notifyAll.
D)None of the above.
Question
An ExecutorService object is created by calling a static method of which class?

A)Executor.
B)Executors.
C)ExecutorService.
D)Thread.
Question
If a thread calls __________,then every thread waiting for the object becomes eligible to acquire the lock.

A)signalEach.
B)signalAll.
C)signal.
D)signalMethods.
Question
When using Java's built-in monitors,every object has a(n)________ or a(n)________ that the monitor ensures is held by a maximum of only one thread at any time.

A)monitor lock,intrinsic lock.
B)built-in lock,free lock.
C)mutual exlcusion lock,synchronization lock.
D)None of the above.
Question
You can simulate atomicity by ensuring that ________.

A)at least one thread carries out its operations on an object at a time.
B)two threads carry out their operations on an object in parallel.
C)only one thread carries out its operations on an object at a time.
D)None of the above.
Question
The Callable interface declares this method.

A)get.
B)call.
C)run.
D)execute.
Question
SwingWorker method ________ executes a long computation in a worker thread.

A)execute.
B)performCalculation.
C)doInBackground.
D)None of the above.
Question
The submit method,when passed a Callable,returns an object of this type.

A)Future.
B)Callable.
C)Runnable.
D)Executor.
Question
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)lock.
B)signal.
C)sleep.
D)await.
Question
The ________ thread should be used to perform all tasks that manipulate GUI components,because they are not thread safe.

A)event-handling.
B)event-dispatch.
C)GUI-handling.
D)None of the above.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/25
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 26: Multithreading
1
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.
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.
C
2
When a thread obtains the monitor lock on an object,then determines that it cannot continue with its task on that object until some condition is satisfied,the thread can call Object method ________;this releases the monitor lock on the object,and transitions the thread waits to the waiting state.

A)waitForOtherThreads.
B)stop.
C)waitForCondition.
D)wait.
D
3
Which of the following is not true of ExecutorService?

A)It is a subinterface of Executor.
B)It is an object that can be run in a separate thread.
C)It declares method shutdown.
D)It manages a group of threads.
B
4
A new thread begins its life cycle by transitioning to the __________ state.

A)runnable.
B)waiting.
C)terminated.
D)new.
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
5
This class is used to help implement mutual exclusion.

A)MutEx.
B)Condition.
C)Lock.
D)Signal.
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
6
When a __________ method or block is running on an object,the object is locked so no other such method can run on that object at the same time.

A)synchronized.
B)shared.
C)thread.
D)writeable.
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
7
The main method executes in the ________ thread of execution.

A)starting
B)main
C)local
D)None of the above.
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
8
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.
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
9
The BlockingQueue interface declares which two methods for blocked adding and blocked removing of elements from a circular buffer?

A)put and take.
B)add and remove.
C)push and pop.
D)place and get.
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
10
The preferred means of creating multithreaded Java applications is by implementing the ________ interface.An object of a class that implements this interface represents a task to perform.

A)Thread.
B)Runner.
C)Runnable.
D)None of the above.
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
11
The ArrayBlockingQueue method ________ returns the number of elements currently in the ArrayBlockingQueue?

A)size.
B)length.
C)getSize.
D)getLength.
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
12
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.
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
13
In a producer/consumer relationship,the ________ portion of an application generates data and stores it in a shared object,and the ________ portion of an application reads data from the shared object.

A)consumer,producer.
B)producer,consumer.
C)outputter,inputter.
D)None of the above.
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
14
Interface ExecutorService provides the ________ method,which returns control to its caller either when all tasks executing in the ExecutorService complete or when the specified timeout elapses.

A)waitForTermination.
B)wait.
C)awaitTermination.
D)None of the above.
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
15
Which of the following is true for a correct producer/consumer relationship with one producer,one consumer,and a 5-cell buffer?

A)The producer can produce when all cells are full.
B)The consumer can consume when all cells are full.
C)The consumer can consume when all cells are empty.
D)None of the above.
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
16
When a thread executing a synchronized statement (or method)completes or satisfies the condition on which another thread may be waiting,it can call Object method ________ or ________ to allow a waiting thread or all waiting threads to transition to the runnable state again.

A)notifyThread,notifyAllThreads.
B)wakeUpThread,wakeUpAllThreads.
C)notify,notifyAll.
D)None of the above.
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
17
An ExecutorService object is created by calling a static method of which class?

A)Executor.
B)Executors.
C)ExecutorService.
D)Thread.
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
18
If a thread calls __________,then every thread waiting for the object becomes eligible to acquire the lock.

A)signalEach.
B)signalAll.
C)signal.
D)signalMethods.
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
19
When using Java's built-in monitors,every object has a(n)________ or a(n)________ that the monitor ensures is held by a maximum of only one thread at any time.

A)monitor lock,intrinsic lock.
B)built-in lock,free lock.
C)mutual exlcusion lock,synchronization lock.
D)None of the above.
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
20
You can simulate atomicity by ensuring that ________.

A)at least one thread carries out its operations on an object at a time.
B)two threads carry out their operations on an object in parallel.
C)only one thread carries out its operations on an object at a time.
D)None of the above.
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
21
The Callable interface declares this method.

A)get.
B)call.
C)run.
D)execute.
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
22
SwingWorker method ________ executes a long computation in a worker thread.

A)execute.
B)performCalculation.
C)doInBackground.
D)None of the above.
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
23
The submit method,when passed a Callable,returns an object of this type.

A)Future.
B)Callable.
C)Runnable.
D)Executor.
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
24
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)lock.
B)signal.
C)sleep.
D)await.
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
25
The ________ thread should be used to perform all tasks that manipulate GUI components,because they are not thread safe.

A)event-handling.
B)event-dispatch.
C)GUI-handling.
D)None of the above.
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 25 flashcards in this deck.