Define multi-threaded programming in java using locks

Assignment Help JAVA Programming
Reference no: EM13770906

Title: Multi-threaded Programming in Java Using Locks

Objectives: To practice programming cooperating, synchronized multiple threads of execution.

Description: In this programming assignment you will simulate the deposits and withdrawals made to a fictitious bank account. In this case the deposits and withdrawals will be made by synchronized threads. Synchronization is required for two reasons - (1) mutual exclusion (updates cannot be lost) and (2) because a withdrawal cannot occur if the amount of the withdrawal request is greater than the current balance in the account. This means that access to the account (the shared object) must be synchronized. This application requires cooperation and communication amongst the various threads (cooperating synchronized threads). (In other words, this problem is similar to the producer/consumer problem where there is more than one producer and more than one consumer process active simultaneously.) If a withdrawal thread attempts to withdraw an amount greater than the current balance - then it must block and wait until a deposit has occurred before it can try again. As we covered in the lecture notes, this will require that the deposit threads signal all waiting withdrawal threads whenever a deposit is completed.

1. To keep things relatively simple as well as to see immediate results from a series of transactions (deposits and withdrawals) assume that deposits are made in amounts ranging from $1 to $200 (even dollars only) and withdrawals are made in amounts ranging from $1 to $50 (again, even dollars only).

2. You should have three deposit threads and four withdrawal threads executing simultaneously.

3. Once a deposit thread has executed, put it to sleep for a millisecond or so (depends a little bit on the speed of your system as to how long you will want to sleep the depositor threads - basically we want to ensure a lot more withdrawals than deposits) to allow other threads to execute. This is the only situation in which a deposit thread will block.

4. Once a withdrawal thread has executed, have it yield to another thread (don't put it to sleep though). This will prevent a single withdrawal thread from gaining the CPU and then executing a long sequence of withdrawal operations. Withdrawal threads block if they attempt to withdraw more than the current balance in the account.

5. Assume all threads have the same priority.

6. The output from your program must look reasonably similar to the sample output shown below.

7. Do not put the threads into a counted loop for your simulation. In other words, the run() method should be an infinite loop.

8. Do not use the Java synchronized statement. I want you to handle the locking and signaling yourself.

Reference no: EM13770906

Questions Cloud

How would you conclusion change for the winter months : How would you conclusion change for the winter months, if bad weather makes it likely for traffic jams on the highway to increase to 6 days per month?
Significance of effective planning for work place emergencie : What is the significance of effective planning for work place emergencies - The effectiveness of an emergency plan depends on the ability of the plan to handle prevent and give guidelines on how to handle emergencies.
Cross-border movements of goods : Why have the governments in almost every country been liberalizing cross-border movements of goods, services, and resources?
Barbow after-tax weighted average cost of capital : Calculate Barbow's after-tax weighted average cost of capital, using the data in the balance sheet above.
Define multi-threaded programming in java using locks : Define Multi-threaded Programming in Java Using Locks, To practice programming cooperating, synchronized multiple threads of execution
Several factors in the market : Olter, Inc. is starting its risk management program for the company and has asked for your help in determining critical risk measurements for the firm. The company has identified several factors in the market that they believe are critical for you..
Assignment related to dismissal meeting : Imagine that you are an office manager and you have been tasked with the job of coordinating and heading the dismissal meeting for an employee layoff.
The electronic communications privacy act : One reason employers use to justify giving honesty or integrity tests is: The Electronic Communications Privacy Act of 1986 (ECPA)
Describe the two teaching strategies : Describe and then justify two teaching strategies. The key features of each strategy. The learning context in which their use is identified in the literature as being most appropriate.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Write an application that extends jframe

Write an application that extends JFrame and that displays a phrase in every font size from 6 through 20.

  Design an application for pizza order process

Create an application to take and procedure a pizza order. The user should be able to make pizza order choices from listboxes, and the application should show the order price.

  How to detect the correct ip address and run it locally

When you compile the two modules, with disabling the package statement, it runs on one single machine, that's running the server

  Write an application that displays all even numbers

Write an application that displays all even numbers from 2 to 100 inclusive, and that starts a new line after every multiple of 20 ( 20, 40, 60, and 80). Save the file as EvenNums. java

  Implement/update specific methods for the dfs of a graph

show the DFS order of vertices in the graph, and for each node, specify its parent node in the search (the node from which the currect node was reached). Moreover, display for each node the discovery and finishing time, to check that the Parenthesis ..

  Java program to ask user to enter favorite color

Write a Java program to ask the user to enter favorite color, a favorite food, favorite animal, and first name of a friend or relative.

  Implement a simple paddle ball game

Implement a simple paddle ball game. Paddle Ball Game Overview The paddle ball game is a simplification of the Pong game. In the Pong game, a ball is moving around the display, bouncing off walls.

  Most of the companies use virtualization to make test

write a 200- to 300-word short-answer response to the following many companies use virtualization to create test

  Write down the business needs for a computer program and

write the business requirements for a computer program and identify which entities are to be modeled using object

  Socket programming modify the translate program and

socket programming modify the translate program and dictionary program. modify the programs to handle multiple user

  These are more specialized versions of the pizzaorders you

your pizza shop expands and now handles delivery orders and sit down orders in a restaurant setting. there are

  Write a method compact that removes all zeroes

Write a program that reads a text file (compact.txt) and stores the integers in an array.  Your instructor will provide this text file.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd