Multiple Choice
Assume two threads share a BankAccount object with balance of zero (0) , and that the BankAccount class provides deposit and withdraw methods and has a ReentrantLock named myLock, as shown below. Note that only the deposit method uses the lock. 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 void deposit(int dollars)
{
MyLock.lock()
Int newBalance = balance + dollars;
System.out.println("depositing") ;
Balance = newBalance;
MyLock.unlock()
}
Public void withdraw(int dollars)
{
Int newBalance = balance - dollars;
System.out.println("withdrawing") ;
Balance = newBalance;
}
A) The balance could be zero or positive.
B) The balance is zero.
C) The balance could be zero or negative.
D) The balance is positive.
Correct Answer:

Verified
Correct Answer:
Verified
Q4: Which phrase best describes the purpose of
Q19: Which constructor can be used to create
Q34: _ occur(s) if the effect of multiple
Q40: Calling the wait method in synchronized code
Q60: Assume two threads share a BankAccount object
Q62: A waiting thread is blocked until another
Q64: Examine the SharedData class shown below. Suppose
Q66: Consider an old fashioned telephone booth that
Q74: A GUI should be responsive to the
Q78: Given a two-CPU machine and four threads,