Question
Java: Threads/Synchronization primitives. Need some help getting this started. This assignment introduces Java threads and synchronization primitives. Students will need to take care to avoid
Java: Threads/Synchronization primitives.
Need some help getting this started.
This assignment introduces Java threads and synchronization primitives. Students will need to take care to avoid a race condition in their solution.
Instructions
A set of N customers have accounts at the local bank, each funded with 10000 dollars. Each customer will initiate T transactions during the simulation. Half of the time the customer's account will receive between $1 and $500 (chosen randomly) from one of the other accounts (also chosen randomly), the other half the time the customer will give between $1 and $500 to one of the other accounts. If a transaction would cause a customer's balance to fall below zero, it is aborted.
Exactly D transactions occur during each day, until the last day where there may be fewer than D transactions. At the end of each day the bank calculates the interest earned by each of the N accounts as 3*balance/10000 (an integer amount); this interest is added to the account immediately. The simulation then displays the total interest paid for that day, and the number of transactions each customer conducted on that day.
Each customer will be implemented as a Java thread. The values of N, D and T are prompted from the user when the simulation begins.
At the end of the simulation the program prints account balance for each customer and the total balance of all accounts; the total interest paid, and the total starting balance (which is N*10000).
To avoid a race condition you will need to synchronize access to the various resources in the system. Getting the interest calculation and end-of-day to work correctly will require keeping a count of all transactions, to prevent each customer from generating new transactions until after that day's interest has been calculated. When testing your program use a large number for T and a small number for N, so that it is more likely you discover a race condition, if one exists
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started