Question: Problem 1 - Threads and Concurrency The following exercise shows what can happen when two threads (here Personl and Person2) share the same object (here

Problem 1 - Threads and Concurrency The following exercise shows what can happen when two threads (here Personl and Person2) share the same object (here a common bank account). For that, you are going to write a program that will include two classes: Account and JobPersonlAndPerson2. The Account class is very simple. It includes: A private attribute balance initialized to 100 representing the current account balance. A withdraw method allowing to withdraw a certain amount from the account. Here it is in detail: class Account { private int balance = 100; public int getBalance 0{ return balance; } public void withdraw(int amount){ balance = balance - amount; // end class Account The JobPersonlAndPerson2 class implements Runnable and represents the behavior that Personl and Person2 both have. Their behavior is quite particular since Personl and Person2 fall asleep very often and in particular while they are withdrawing. This class contains: An attribute of type Account representing the bank account of Personl and Person2. A method makeWithdrawal(int amount) allowing Personl or Person2 to make a withdrawal from their bank account. The behavior of this method is as follows: the person wishing to make the withdrawal checks the balance, then falls asleep 500 ms, then on waking (after 500 ms) makes the withdrawal. The name of the person making the withdrawal must be reported. A run() method describing the behavior of Personl and Person2. This involves making a loop (for example 10) withdrawals of 10 euros. Finally, the main method creates two threads (Personl and Person2) with the same Runnable here of type JobPersonlAndPerson2), names them Personl and Person2, then starts them. Write the JobPersonlAndPerson2" java class
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
