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. If the balance after all thread calls is 0, which statement is definitely true?
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) The calls were interleaved: thread one, thread two, thread one, thread two, …
B) The first call was to the deposit method.
C) The last call was to the withdraw method.
D) Each individual call to the deposit and withdraw methods ran to completion.
Correct Answer:
Verified
Q42: Assume two threads share a BankAccount object
Q46: Examine the SharedData class shown below. Suppose
Q50: Consider the following change to the deposit
Q50: A waiting thread is blocked until another
Q51: _ allow a thread to temporarily release
Q52: Examine the SharedData class shown below. Suppose
Q54: Consider the addFirst method of the LinkedList
Q55: The _ method is called by a
Q58: If a thread sleeps after acquiring a
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