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;
}
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
Q42: The _ method is useful only if
Q58: Examine the SharedData class shown below. Suppose
Q60: Assume two threads share a BankAccount object
Q64: Stale data occurs in multi-CPU machines when
Q65: When is it a good idea to
Q69: Under what conditions are locks unnecessary for
Q72: Stale data occurs in multi-CPU machines when
Q74: Under what circumstances will a call to
Q79: Consider an old fashioned telephone booth that
Q80: Which of the following scenarios may not
Unlock this Answer For Free Now!
View this answer and more for free by performing one of the following actions
Scan the QR code to install the App and get 2 free unlocks
Unlock quizzes for free by uploading documents