Exam 21: Multithreading

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags

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:
Verified

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:
Verified

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:
Verified

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
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)