Write a program to simulate the behavior of the philosophers

Assignment Help JAVA Programming
Reference no: EM13332141

Dining Philosophers Problem

Imagine n philosophers who spend their lives just thinking and feasting. They sit around a circular table, each in front of his own plate. However, there are only n chopsticks available. Each philosopher thinks for some time. When he gets hungry, he tries to pick up the two chopsticks that are closest to him. If both chopsticks are available, he takes them and eats for a while. After a philosopher finishes eating, he puts down the chopsticks and again starts to think.

To not disrupt each others thoughts, philosophers do not communicate with each other and try to chew silently.

Write a program to simulate the behavior of the philosophers, where each philosopher is a thread and the chopsticks are shared objects.

Notice:

• You must prevent a situation where two philosophers hold the same chop-stick at the same time.
• It must never be the case that a philosopher hold one chopstick and is stuck waiting for another to get the second chopstick, i.e. your program should be deadlock free.
• Extend your program in such a way that philosophers never starve.

Details for submission:

• Submit an executable .jar file named philosopher.jar which includes the source files.
• The program should take as parameter the number of philosophers. Calling java -jar philosopher.jar 7 shall simulate seven philosophers sitting around the table.
• Also, in a text file, provide a user documentation to outline how your program can be compiled and executed.

Reference no: EM13332141

Questions Cloud

What is the take-off speed of the jet : The thrust produced by a single jet engine, m=7300kg, creates a force F=73000N. It takes the jet a distance of d=0.84km to take off. What is the take-off speed of the jet
Current global economy requires intricacy : The current global economy requires intricacy in thinking through business issues. It also requires cultural understanding and negotiation skills as well as innovative and sustainable ideas to solve problems. The problems and possibilities that you w..
What is the radius of the concave surface : A planoconcave lens (n = 1.52) has a focal length of -24.6cm. What is the radius of the concave surface
Evaluate pcu at the equivalence point in the titration : Calculate pCu at the equivalence point in the titration of 20.0 mL of 0.0161 M CuSO4 with 0.0100 M EDTA at pH 8.00.
Write a program to simulate the behavior of the philosophers : Write a program to simulate the behavior of the philosophers, where each philosopher is a thread and the chopsticks are shared objects.
What is the size of the equal installments : A loan of $7000 taken out two years ago is to be repaid in three equal installments due now, two years from now, and three years from now respectively. What is the size of the equal installments if interest on the debt is 12% compounded monthly?
The topic is managerial accounting : The topic is managerial accounting / cost accounting.
How to evaluate the molar concentration of mg2+ : A 200.0-mL sample of the same tap water required 47.86 mL of the standard EDTA for titration at pH 10 using calmagite indicator. Calculate the molar concentration of Mg2+ in the tap water.
An accrual basis taxpayer : For each of the following independent situations, state which concept(s) is (are) responsible for the treatment and EXPLAIN how each concept is applied.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Write an application that enables users to enter student ID

Write an application that enables users to enter student ID and three exam scores. Provide a method to compute and returnthe overall exam average.  Provide another method that prints all scores and the average value formatted with no digits to the ri..

  Class sorter which contains methods for selection sort

Write a class Sorter which contains methods for selection sort, insertion sort and bubble sort (start with the code below). Then create a client class which asks user to enter ten numbers using arrays. Then the program asks user which sorting algo..

  Ticketmaster

TICKETMASTER - this class will have: a service charge = $8.00 per ticket, tax = .085 current amount of all tickets sold. Its responsibilities are printing a list of events for sale, looking up an event for a customer, and selling a ticket to the e..

  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.

  Write a while loop that lets the user enter a number

1) Write a while loop that lets the user enter a number. The number should then be multiplied by 10, and stored in a variable called product. The loop should then iterate as long as product contains a value less than 100.

  Design a java program that simulates a slot machine

Design a java program that simulates a slot machine. When the program runs, it should do the following: Ask the user to enter the amount of money he or she wants to insert into the slot machine. ? Instead of displaying images, the program will random..

  Write a java program to perform matrix multiplication

In this project you need to write a java program called to perform matrix multiplication and

  Application named arithmeticmethods

Create an application named ArithmeticMethods whose main() method holds two integer variables. Assign values to the variables. In turn, pass each value to methods named displayNumberPlus10()

  Can linear search algorithm be encoded using recursion

Determine the average amount of time people spend waiting for tables and provide examples from the "real world" of unsorted lists, sorted lists, indexed lists, lists that permit duplicate elements, and lists that do not permit duplicate elements

  Java program to compare two variables if they are equal

Write down program which will ask user to initialize two character arrays, program must compare two variables if they are equal.

  User session mgr - socket and thread programs

User Session Mgr - Socket and Thread Programs

  Modify each sorting algorithm

Modify each sorting algorithm so that it keeps track of the number of comparisons it performs and the number of exchanges (swaps) it performs during a single sorting operation. Keep track of these numbers using two long integer counters

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