Multiple Choice
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() ;
}
A) 0
B) 15 or 25
C) 45
D) -5
Correct Answer:

Verified
Correct Answer:
Verified
Q19: Which constructor can be used to create
Q23: a(n. _ uses a small number of
Q33: When a sleeping thread is interrupted, a(n)
Q45: Insert the statement that would start the
Q48: Suppose that the class XYZ implements the
Q49: Class MyClass has two ReentrantLock objects, myLock1
Q56: The thread that calls signalAll must own
Q56: Examine the SharedData class shown below. Suppose
Q62: Each thread runs for a short amount
Q71: Which are ways that a thread can