Consider the following conditions

Assignment Help JAVA Programming
Reference no: EM13709555

Problem 1 A savings account object holds a non-negative balance, and provides deposit(k ) and withdraw(k ) methods, where deposit(k ) adds k to the balance, and withdraw(k ) subtracts k, if the balance is at least k, and otherwise blocks until the balance becomes k or greater. getbalance() gives the current balance.

1. Implement this savings account using locks and conditions (use java.util.concurrent.locks.ReentrantLock). Test by using the 3 functions. 2. Now suppose there are two kinds of withdrawals: ordinary and preferred. Devise an implementation that ensures that no ordinary withdrawal occurs if there is a preferred withdrawal waiting to occur.

Problem 2 Consider the following conditions: An enqueuer waiting on a full-queue or a dequeuer waiting on an empty queue sleep indefinitely, unless woken up by another thread. A thread must send a signal ONLY when it adds an element to an empty queue or removes an element from a full-queue.

1. Implement a bounded partial queue using a signaling mechanism that signals to all waiting dequeuers.

2. Implement the bounded partial queue by using a signaling mechanism (your own scheme) that signals to only one waiting dequeuer or enqueuer, and ensure that the lost-wake-up problem does not happen. Problem 3 We have n threads, each of which executes method foo() followed by bar(). We want to add synchronization to ensure that no thread starts executing bar() until all threads have finished executing foo(). To achieve this, we will insert some barrier code between the two methods. Implement the following two schemes for barrier code: . Use a shared counter protected by test-and-test-and-set lock. Each thread locks the counter, increments it, releases the lock, and repeatedly reads the counter until it reaches n. . Use an n-element Boolean array A. Initially all entries are 0. When thread 0 executes its barrier, it sets b[0] to 1, and repeatedly reads b[n - 1] until it becomes 1. Every other thread i, repeatedly reads b[i - 1] until it becomes 1, then it sets b[i] to 1, and repeatedly reads b[n - 1] until it becomes 1. Implement both these schemes in Java. Each of the methods foo() and bar() just sleeps for 20 milliseconds. Test the two schemes for n = 16. Run each scheme at least ten times, measure the total runtime in each test run, discard the highest and lowest values, take the average, and use it to compare the two schemes. Which performs better? Can you explain the reason?

Reference no: EM13709555

Questions Cloud

What is an auction : What is an Auction? E Bay is a market leader in online auction sites. Discuss SWOT for E bay using your web sources?.
In the questions 2 interviews suppose to happen : Developing cultural competence requires examining biases and prejudices, developing cross - cultural skills, searching for role models, and spending as much time as possible with other people who share a passion for cultural competence.
What are the essential properties of presupposition : What are the essential properties of presupposition? 1b. To what extent is presupposition a pragmatic phenomenon?1c. What is the projection problem for presupposition?
The us should give illegal immigrants amnesty : Write a paper on Topic "The U.S should give illegal immigrants amnesty"
Consider the following conditions : Consider the following conditions: An enqueuer waiting on a full-queue or a dequeuer waiting on an empty queue sleep indefinitely, unless woken up by another thread. A thread must send a signal ONLY when it adds an element to an empty queue or remove..
You are managing a systems development team for a company : You are managing a systems development team for a company you are familiar with. The company wants to implement a new accounting information system. Your team has been asked to review the process prior to implementation.
E-business assignment and the business law project : Just to clarify, this about will cover both the e-business assignment and the business law project?  this is included two document for two different subjects (first one is project 10-12 page. The second document is assignment 1-2 page only.)
Demonstrate your learning : Hand-in Assignments are one way for you to demonstrate your learning. The Hand-in Assignments provide an opportunity to apply concepts and strategies to an authentic context.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Develop a web-based application the server-side part of

develop a web-based application. the server-side part of the application must be developed using java servlets

  Java class to accept a user-s hourly rate of pay

Write a class that accepts a user's hourly rate of pay and the number of hours worked. Display the user's gross pay, the withholding tax (15% of gross pay), and the net pay (gross pay - withholding).

  App that allows the user to enter a series of numbers

Write an app that allows the user to enter a series of numbers and manipulate them. The app should provide users with the option of adding or multiplying the numbers.

  Create file lab7.java with a main method.

Create file Lab7.java with a main method. Inside your main method, write a segment of code which instantiates an object of the Student class (This class has been created for you in the  Student.java  file that is provided as part of this lab).

  Java program that asks the user for 100 values

Write a Java program that asks the user for 100 values (or generates these randomly) and stores and displays only the distinct values. Hint: use an array to store and display these values.

  Objectivesto gain experience with arrays to gain

objectivesto gain experience with arrays. to gain experience with generic algorithms.documentationexplain

  Compute the sum of the first n positive odd integers

Write JAVA program that will compute the sum of the first n positive odd integers.  For example, if n is 5, you should compute 1 + 3 + 5 + 7 + 9.

  That uses a library database of books

Write a Java program that uses a library database of books and patron data, as described in Exercise R22.2. Patrons should be able to check out and return books

  Write a class that has the subsequent fields

Write a class that has the subsequent fields: first name, last name, id number, department, payRate, hoursWork with constructors that accepts the subsequent values as arguments and assigns them to the appropriate fields.

  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.

  Identify the 5 code elements

Identify the 5 code elements for a Password class. Things like: class, instance, and final variables, accessor and mutator method, public and private specifiers for methods and member variables.i need to provide detail and descriptions for each code ..

  What are mobile oss you have personally used explain the

write a 200- to 300-word short-answer response to the following bull what are mobile oss you have personally used?

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