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

  A class for counting the number of people

Specification: A class for counting the number of people in a room. This might be used to control how many people are allowed into a club with a doorman.

  Days alive calculator

The context for this assignment (all parts) is a ‘Days Alive Calculator' - a small desktop application for calculating the number of days someone has been alive based on the date of birth and a second date, which may be today's date or some other ..

  A fault is fundamentally a deviation from expected behavior

write a 200- to 300-word short-answer response to the following a fault is basically a deviation from expected

  Write a java program that prompts the user

Write a Java program that prompts the user to input three numbers.  This program should then output the numbers in an ascending order.

  Java :a user-defined starting position (other than 0,0)

modifying the program so that it can start from a user-defined starting position (other than 0,0) and search for a user defined ending point (other than row-1, column-1) .

  Functioning java application.

Your final project must be a complete and functioning Java application.

  Powerful pain reliever are consumers with headaches

Your target market for the most powerful pain reliever are consumers with HEADACHES. Start with goals and objectives. Do a SWOT. What information is most important for your market? Do some market research.

  Calculates the cutoff frequency in a simple rc circuit

Write a simple Java application which calculates the cutoff frequency in a simple RC circuit.

  Ood methodology

Your local police department wants to design new software to keep track of people, property, and criminal activity. List at least three classes you think should be in the design. For each class, identify some data members and methods.

  Given a hash function hkey prepare a java simulation

given a hash function hkey prepare a java simulation program to determine each of the subsequent quantities after

  Elliptic curve encryption

write a program to implement Elliptic Curve encryption/decryption and program will read parameters, plaintext and ciphertextfrom a file named "input.txt" (under the same directory).

  Create listener objects for each jcombobox

Create listener objects for each JComboBox that set the background color of the panel when the user selects an integer. Use the current values supplied by the JComboBox objects to determine the background color.

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