Exam 20: Multithreading
Exam 1: Introduction96 Questions
Exam 2: Fundamental Data Types103 Questions
Exam 3: Decisionseasy99 Questions
Exam 4: Loops100 Questions
Exam 5: Methods94 Questions
Exam 6: Arrays and Arraylists100 Questions
Exam 7: Inputoutput and Exception Handling100 Questions
Exam 8: Objects and Classes101 Questions
Exam 9: Inheritance and Interfaces99 Questions
Exam 10: Graphical User Interfaces54 Questions
Exam 11: Advanced User Interfaces91 Questions
Exam 12: Object-Oriented Design100 Questions
Exam 13: Recursion100 Questions
Exam 14: Sorting and Searching99 Questions
Exam 15: The Java Collections Framework100 Questions
Exam 16: Basic Data Structures94 Questions
Exam 17: Tree Structures100 Questions
Exam 18: Generic Classes78 Questions
Exam 19: Streams and Binary Inputoutput82 Questions
Exam 20: Multithreading82 Questions
Exam 21: Internet Networking74 Questions
Exam 22: Relational Databases75 Questions
Exam 23: XML74 Questions
Exam 24: Web Applications74 Questions
Select questions type
Which phrase best describes the purpose of a lock used in an object in one or more of its methods?
(Multiple Choice)
4.8/5
(32)
What is likely to be true when thread one is downloading a 1MB file while thread two is downloading another 1MB file?
(Multiple Choice)
4.9/5
(33)
Which method do you call to make a thread ineligible to run on the CPU for a set number of milliseconds?
(Multiple Choice)
4.8/5
(32)
Examine the SharedData class shown below. Suppose two threads are created so that each has access to the same SharedData object. Thread one calls setSharedData ten times with values 1...10 respectively, sleeping for a random number of milliseconds between calls. Thread two calls getSharedData eight times, also sleeping for a random number of milliseconds between calls. Which of the following could be the last two values received by thread two?
Public class SharedData
{
Private int value;
Public void setSharedData(int n)
{
Value = n;
}
Public int getSharedData()
{
Return value;
}
}
(Multiple Choice)
4.9/5
(40)
The ________ method stops the current thread for a given number of milliseconds.
(Multiple Choice)
5.0/5
(40)
The Runnable interface includes which method(s)?
I public void run(Runnable runnable)
II public void run()
III public void start()
(Multiple Choice)
4.9/5
(41)
"Livelock" occurs when one thread runs continuously, while another thread never does. Which of the following is sufficient to cause livelock?
I Thread one is in an infinite loop
II Thread one possesses a lock and does not unlock it, but thread two requires the lock
III Thread one requires a lock, but thread two possesses the lock
(Multiple Choice)
4.9/5
(33)
When a sleeping thread is interrupted, a(n) ____________________ is generated.
(Multiple Choice)
4.8/5
(37)
Suppose that the class XYZ implements the interface Runnable. Which code creates a thread object and makes it available to the scheduler to be executed?
(Multiple Choice)
4.8/5
(36)
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.
(Multiple Choice)
4.7/5
(39)
Which constructor can be used to create a new thread associated with a Runnable object?
(Multiple Choice)
4.8/5
(35)
Class MyClass has two ReentrantLock objects, myLock1 and myLock2. Suppose thread one acquires myLock1 as it enters methodX and immediately completes its CPU time slice. After thread two enters methodY, it acquires myLock2 and tries to acquire myLock1. When thread one resumes, it tries to acquire myLock2. What will happen next?
(Multiple Choice)
4.8/5
(38)
Assume three threads share a BankAccount object with balance of zero (0), a ReentrantLock named myLock, and a condition object on myLock named lowBalanceCondition, as shown below. Thread one calls withdraw(30), then thread two calls withdraw(20)and thread three calls deposit(45). If the starting balance is 0, what is the balance after the three calls?
Public void deposit(int dollars)
{
MyLock.lock();
Int newBalance = balance + dollars;
System.out.println("depositing");
Balance = newBalance;
MyLock.unlock();
}
Public void withdraw(int dollars)
{
MyLock.lock();
While (balance < dollars)
{
LowBalanceCondition.await();
}
Int newBalance = balance - dollars;
System.out.println("withdrawing");
Balance = newBalance;
MyLock.unlock();
}
(Multiple Choice)
4.7/5
(48)
A(n) ____ uses a small number of threads to execute a large number of runnables.
(Multiple Choice)
4.8/5
(38)
Examine the SharedData class shown below. Suppose two threads are created so that each has access to the same SharedData object. Thread one calls setSharedData eight times with values 1...8 respectively, sleeping for 30 milliseconds between calls. Thread two calls getSharedData eight times, also sleeping for 30 milliseconds between calls. Which of the following orders of values is not possible for thread two to receive?
Public class SharedData
{
Private int value;
Public void setSharedData(int n)
{
Value = n;
}
Public int getSharedData()
{
Return value;
}
}
(Multiple Choice)
4.9/5
(34)
Each thread runs for a short amount of time, called a ____________________.
(Multiple Choice)
4.7/5
(34)
Insert the statement that would start the following thread.
Thread firstThread = new Thread(myRunnable);
____________________
(Multiple Choice)
4.8/5
(37)
Which are ways that a thread can be blocked?
I when it is sleeping
II waiting for a lock to be available
III waiting after calling the await method
(Multiple Choice)
4.9/5
(32)
When a thread is interrupted, the most common response is to terminate the ____________ method.
(Multiple Choice)
4.9/5
(40)
Showing 41 - 60 of 82
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)