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
Q3: The _ method is useful only if
Q18: Which argument(s) present(s) the best case(s) for
Q30: What happens when a thread calls the
Q41: What happens if we try to start
Q55: To start a thread, you should first
Q67: What is the relationship between synchronized code
Q68: In the initial release of the Java
Q77: Which of the following does not create
Q78: Given a two-CPU machine and four threads,
Q80: When is it a good idea to