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
Q62: A GUI should be responsive to the
Q65: When is it a good idea to
Q72: Stale data occurs in multi-CPU machines when
Q73: Class MyClass has two ReentrantLock objects, myLock1
Q74: Under what circumstances will a call to
Q77: Assume three threads share a BankAccount object
Q78: "Livelock" occurs when one thread runs continuously,
Q79: Consider an old fashioned telephone booth that
Q80: Which of the following scenarios may not
Q81: Which are ways that a thread can
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