Question: 9.6 Write a program that has multiple threads that make deposits and withdrawals in a shared bank account program without using locks. Demonstrate how the

9.6 Write a program that has multiple threads that make deposits and withdrawals in a shared bank account program without using locks. Demonstrate how the bank account can become corrupted.

Assignment Requirements:

Exercise 9.6 a. Use a single shared integer buffer. b. The deposit amount is a random number 0 <= deposit <= 100 c. Use Main9Point6.java to test your classes. d. Program output is similar to Output9.10.txt.

Main9Point6.java

class Main9Point6 { // This starts everything

public static void main (String argv[]) {

UnsynchronizedBankAccount account = new

UnsynchronizedBankAccount(); // shared integer buffer

// start threads

new Thread (new Withdrawer(account, 1)).start();

new Thread (new Depositor(account, 1)).start();

new Thread (new Withdrawer(account, 2)).start();

new Thread (new Depositor(account, 2)).start();

}

}

Output9.10.txt

Withdrawer-2: 7

Withdrawer-1: 76

Depositor-2: 76

Depositor-1: 7

Withdrawer-2: 30

Depositor-2: 30

Withdrawer-1: 2

Depositor-1: 2

Withdrawer-2: 89

Depositor-2: 89

Depositor-1: 73

Withdrawer-1: 73

Withdrawer-1: 41

Withdrawer-2: 57

Depositor-1: 41

Depositor-2: 57

Withdrawer-2: 89

Depositor-2: 89

Withdrawer-1: 36

Depositor-1: 36

Depositor-2: 56

Depositor-1: 14

Withdrawer-1: 56

Withdrawer-2: 14

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!