Services
Discover
Ask a Question
Log in
Sign up
Filters
Done
Question type:
Essay
Multiple Choice
Short Answer
True False
Matching
Topic
Computing
Study Set
Big Java Binder Early Objects
Exam 21: Multithreading
Path 4
Access For Free
Share
All types
Filters
Study Flashcards
Practice Exam
Learn
Question 1
Multiple Choice
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.
Question 2
Multiple Choice
What is the relationship between synchronized code and code that is locked using a ReentrantLock object?
Question 3
Multiple Choice
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.
Question 4
Multiple Choice
Which exception must be caught or declared when calling the sleep method?
Question 5
Multiple Choice
Insert the statement that would start the following thread. Thread firstThread = new Thread(myRunnable) ; ____________________
Question 6
Multiple Choice
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
Question 7
Multiple Choice
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() ;
Question 8
Multiple Choice
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?
Question 9
Multiple Choice
To start a thread, you should first construct an object from a class that implements the ____________ interface.
Question 10
Multiple Choice
The ____________ occurs when a thread that is not running is interrupted.
Question 11
Multiple Choice
The sleep method is terminated with a(n) __________ whenever a sleeping thread is interrupted.
Question 12
Multiple Choice
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; }
Question 13
Multiple Choice
When a sleeping thread is interrupted, a(n) ____________________ is generated.
Question 14
Multiple Choice
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 { . . . }