Examlex

Solved

Assume Three Threads Share a BankAccount Object with Balance of Zero

question 51

Multiple Choice

Assume three threads share a BankAccount object with balance of zero (0) , a ReentrantLock named myLock, and a condition object on myLock named lowBalanceCondition, as shown below. Thread one calls withdraw(30) , then thread two calls withdraw(20) and thread three calls deposit(45) . If the starting balance is 0, what is the balance after the three calls? public void deposit(int dollars)
{
MyLock.lock() ;
Int newBalance = balance + dollars;
System.out.println("depositing") ;
Balance = newBalance;
MyLock.unlock() ;
}
Public void withdraw(int dollars)
{
MyLock.lock() ;
While (balance < dollars)
{
LowBalanceCondition.await() ;
}
Int newBalance = balance - dollars;
System.out.println("withdrawing") ;
Balance = newBalance;
MyLock.unlock() ;
}


Definitions:

Aardvark Ltd

A hypothetical or specific company named Aardvark Ltd, without context its nature or industry cannot be defined.

Budgeted Production

The quantity of products that a company plans to produce over a specific period, often used for planning and resource allocation.

Finished Goods

Products that have completed the manufacturing process but have not yet been sold or distributed to the end user.

Production Hold-Ups

Delays or interruptions in the manufacturing process that can lead to increased costs and extended production timelines.

Related Questions