Multiple Choice
Assume three threads share a BankAccount object with balance of zero (0) , a ReentrantLock named myLock, and has 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 and after the waiting threads have had a chance to run? public void deposit(int dollars)
{
MyLock.lock() ;
Int newBalance = balance + dollars;
System.out.println("depositing") ;
Balance = newBalance;
LowBalanceCondition.signalAll() ;
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() ;
}
A) 0
B) 15 or 25
C) 45
D) -5
Correct Answer:

Verified
Correct Answer:
Verified
Q4: Which phrase best describes the purpose of
Q19: Which constructor can be used to create
Q41: What happens if we try to start
Q64: Examine the SharedData class shown below. Suppose
Q66: Consider an old fashioned telephone booth that
Q67: The Runnable interface has a single method
Q70: If you do not use the Runnable
Q71: Which are ways that a thread can
Q73: Which of the following statements is correct?<br>A)If
Q73: Consider an old fashioned telephone booth that