Multi-threaded programming in java using locks

Assignment Help JAVA Programming
Reference no: EM13762725

Assignment on 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 synchronized threads will make the deposits and withdrawals. 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. No monitors!

Reference no: EM13762725

Questions Cloud

It governance - a hands on approach is the best way : IT Governance - A Hands on Approach is the best way-Prepare a 4- 5-minute one-point argumentative speech present. ation on a topic related to the IT profession or of interest to IT Professionals
Compare and contrast the andy griffith show and i love lucy : Using at least 700 words, compare and contrast The Andy Griffith Show and I Love Lucy.
Processes involved in mechanical and chemical weathering : Describe how weathering activity differs between climates.
Two alternatives are being considered for a customers order : Two alternatives are being considered for a customer's order whose anticipated volume is not yet know. If the firm produces in-house, the fixed cost is $340,000 and variable cost is $2.90 per unit. If the firm chooses to outsource, it will incur a fi..
Multi-threaded programming in java using locks : Assignment on Multi-threaded Programming in Java Using Locks
Large hotel-casion is currently under construction : A large hotel-casion in Las Vegas is currently under construction. There will be an Italian restaurant in the hotel that will serve pizza. Management is trying to decide whether to make the pizza themselves or buy it frozen and simply heat it to cust..
Explain the reasons behind the emergence of dystopian women : Explain the reasons behind the emergence of dystopian women's literature. Explain how dystopian concepts manifest in women's literature.
Envision the present and future role and place of women : Envision the present and future role and place of women. Identify how the borders are currently being redefined in women's writing.
What the five functions of management mean : Write a two page paper on what the five functions of management mean and how you would utilize each of them to successfully put together and lead this project team.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Setting up the form page

Download and save the attached comment CGI mailer script form-mail2.pl to your server's cgi-bin directory, and change the permissions on the script to make it executable (not writable).

  Describe how an eavesdropped can gain access

Describe how an eavesdropped can gain access to the remote server with a relatively modest number of guesses ( Hint:  The eavesdropped starts guessing after the original user has typed all but one character of the password.

  Create an array of five employee objects

Create an array of five Employee objects. Prompt the user to enter data for each Employee. Do not allow duplicate ID numbers to be entered.

  Write a statement to create a jframe object

Write a statement to create a JFrame object with a title of "My GUI Application" - Write a Java statement to have the object from the question above manage its display area by dividing it into 3 rows which have 4 columns each.

  The application with all the specifications should be

the application with all the specifications should be developed based on a graphical user interface.1. implement proper

  Write java program to select pine for furniture company

Write down the Java program for the furniture company. Ask user to select P for Pine, O for Oak or M for Mahogany.

  Question superclass and provide a different implementa

Add a method addText to the Question superclass and provide a different implementa- tion of ChoiceQuestion that calls addText rather than storing an array list of choices.

  Prepare a point class that represents points

Prepare a Point class that represents points on an x, y axis. The data members should be doubles x and y plus an int value called count that represents the number of points presently instantiated

  Anbsp build a student record managing system application by

a.nbsp build a student record managing system application by doing the following1.nbsp create a student inheritance

  Create a class that uses the genetricstack class

Create a new class named GenericStack that specifies a type variable that gives for generics - Use the peek method to return the first item and show that item, and use the size method to return the number of items again and show that value.

  Create java program to find number of days left in that year

Create a Java program called "DaysLeftInYear.java" that outputs the number of days left in that year. use the calendar class to represent dates. Use the DateFormat class to display the current date in the output.

  Write a class named java1306cmis141c801 that performs the

write a class named java1306cmis141c801 that performs the following actions.prompt the user for an int between lower

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