Exam 21: Multithreading
Exam 1: Introduction98 Questions
Exam 2: Using Objects76 Questions
Exam 3: Implementing Classes103 Questions
Exam 4: Fundamental Data Types125 Questions
Exam 5: Decisions120 Questions
Exam 6: Loops128 Questions
Exam 7: Arrays and Array Lists118 Questions
Exam 8: Designing Classes95 Questions
Exam 9: Inheritance101 Questions
Exam 10: Interfaces85 Questions
Exam 11: Inputoutput and Exception Handling109 Questions
Exam 12: Object-Oriented Design104 Questions
Exam 13: Recursion110 Questions
Exam 14: Sorting and Searching109 Questions
Exam 15: The Java Collections Framework110 Questions
Exam 16: Basic Data Structures104 Questions
Exam 17: Tree Structures110 Questions
Exam 18: Generic Classes75 Questions
Exam 19: Graphical User Interfaces76 Questions
Exam 20: Streams and Binary Inputoutput82 Questions
Exam 21: Multithreading82 Questions
Exam 22: Internet Networking74 Questions
Exam 23: Relational Databases75 Questions
Exam 24: XML74 Questions
Exam 25: Web Applications75 Questions
Select questions type
The thread that calls signalAll must own the lock that belongs to the condition object on which signalAll is called. Otherwise, a(n) _______ ________ is thrown.
Free
(Multiple Choice)
4.7/5
(30)
Correct Answer:
B
What is the relationship between synchronized code and code that is locked using a ReentrantLock object?
Free
(Multiple Choice)
4.8/5
(33)
Correct Answer:
B
The _____________ interface is designed to encapsulate the concept of a sequence of statements that can run in parallel with other tasks, without equating it with the concept of a thread, a potentially expensive resource that is managed by the operating system.
Free
(Multiple Choice)
4.7/5
(35)
Correct Answer:
B
Which exception must be caught or declared when calling the sleep method?
(Multiple Choice)
4.8/5
(35)
Insert the statement that would start the following thread. Thread firstThread = new Thread(myRunnable);
____________________
(Multiple Choice)
4.7/5
(38)
Which of the following definitely indicates that a thread has terminated?
I The run method has completed
II The method Thread.interrupted returns true
III The run method catches an InterruptedException
(Multiple Choice)
4.8/5
(40)
Which of the following does not create an object that can run in a thread, assuming the following MyRunnable class declaration? public class MyRunnable implements Runnable { . . . }
I Runnable runnable = new Runnable();
II Runnable runnable = new MyRunnable();
III MyRunnable runnable = new MyRunnable();
(Multiple Choice)
4.8/5
(32)
Consider the following change to the deposit method in Section 21.4: public void deposit(double amount)
{
BalanceChangeLock.lock();
Try
{
Double newBalance = balance + amount;
Balance = newBalance;
}
Finally
{
BalanceChangeLock.unlock();
}
System.out.println("Depositing " + amount + ", new balance is " + balance);
}
What is the consequence of this change?
(Multiple Choice)
4.9/5
(49)
To start a thread, you should first construct an object from a class that implements the ____________ interface.
(Multiple Choice)
4.8/5
(42)
The ____________ occurs when a thread that is not running is interrupted.
(Multiple Choice)
4.8/5
(34)
The sleep method is terminated with a(n) __________ whenever a sleeping thread is interrupted.
(Multiple Choice)
4.7/5
(32)
Assume two threads share a BankAccount object with balance of zero (0), and that the BankAccount class provides synchronized deposit and withdraw methods. Thread one deposits $10 ten times and, concurrently, thread two withdraws $10 ten times. Which statement regarding the balance after all thread calls is definitely true? public synchronized void deposit(int dollars)
{
Int newBalance = balance + dollars;
System.out.println("depositing");
Balance = newBalance;
}
Public synchronized void withdraw(int dollars)
{
Int newBalance = balance - dollars;
System.out.println("withdrawing");
Balance = newBalance;
}
(Multiple Choice)
4.9/5
(39)
When a sleeping thread is interrupted, a(n) ____________________ is generated.
(Multiple Choice)
4.8/5
(35)
Which of the following class declarations could run in a thread?
I public interface MyRunnable extends Runnable { . . . }
II public class MyRunnable extends Runnable { . . . }
III public class MyRunnable implements Runnable { . . . }
(Multiple Choice)
4.9/5
(43)
Which of the following definitely indicates that a thread has been interrupted by another thread?
I The run method has completed
II The method Thread.interrupted returns true
III The run method catches an InterruptedException
(Multiple Choice)
4.8/5
(33)
The ________ method is called by a thread that has just changed the state of some shared data in a way that may benefit waiting threads.
(Multiple Choice)
4.8/5
(40)
What happens when a thread calls the signalAll method of a Condition object connected to a lock, if no other thread had called await on that Condition object?
(Multiple Choice)
4.8/5
(36)
Which argument(s) present(s) the best case(s) for using the Runnable interface rather than extending the Thread class?
I Thread sub-classes are harder to write
II Runnable objects can be passed into thread pools
III Less time is wasted in creating and destroying thread objects
(Multiple Choice)
4.9/5
(31)
____ allow a thread to temporarily release a lock, so that another thread can proceed, and to regain the lock at a later time.
(Multiple Choice)
4.8/5
(36)
Under what circumstances will a call to signalAll not release a blocked thread that has called await?
(Multiple Choice)
4.8/5
(31)
Showing 1 - 20 of 82
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)