Assume two threads share a BankAccount object with balance of zero (0) , and that the BankAccount class provides deposit and withdraw methods as shown below. Thread one deposits $10 ten times and, concurrently, thread two withdraws $10 ten times. Suppose a race condition occurs, and the race is finished first by thread one. What would you expect balance to be after all thread calls? public void deposit(int dollars)
{
Int newBalance = balance + dollars;
System.out.println("depositing") ;
Balance = newBalance;
}
Public void withdraw(int dollars)
{
Int newBalance = balance - dollars;
System.out.println("withdrawing") ;
Balance = newBalance;
}
A) $10
B) $20
C) $0
D) a negative amount
Correct Answer:
Verified
Q25: The _ method does not actually cause
Q34: The _ occurs when a thread that
Q35: a(n. _ uses a small number of
Q37: Which of the following definitely indicates that
Q41: The thread that calls signalAll must own
Q42: The _ method is useful only if
Q47: Examine the SharedData class shown below. Suppose
Q51: _ allow a thread to temporarily release
Q57: Which of the following statements is correct?
A)If
Q63: Calling the wait method in synchronized code
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