Indian cricket team Players at an winning celebration dine at a circular table on which there is a single fork between each Player. Players either eat or think, and always start dinner thinking. To eat, a Player first picks up the fork immediately to his left and, once successful, picks up the fork immediately to his right. When a required fork is not on the table, the Player waits, neither eating nor thinking, until the fork is returned to the table. After eating, a Player returns both forks to the table. No cutlery is required to think. Your task is to model the above scenario in Java. (a) Write a class called Fork with two public methods, ForkpickUp and ForkputDown. The methods should take no arguments and return no result. An instance of Fork should act as a lock to prevent concurrent access. In other words, once ForkpickUp has been called, all further calls to ForkpickUp should block until ForkputDown is called; when ForkputDown is called, one caller (if any) who is blocked should proceed. (b) Write a class called Players which inherits from the Thread class and implements the abstract method run. The Player class should have a single constructor which takes two Fork objects, one representing the fork to the Player’s left, and one to the right. When run, an instance of Player should think for ten seconds, eat for ten seconds and think for ten seconds before terminating.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Indian cricket team Players at an winning celebration dine at a circular table on which there is a single fork between each Player. Players either eat or think, and always start dinner thinking. To eat, a Player first picks up the fork immediately to his left and, once successful, picks up the fork immediately to his right. When a required fork is not on the table, the Player waits, neither eating nor thinking, until the fork is returned to the table. After eating, a Player returns both forks to the table. No cutlery is required to think. Your task is to model the above scenario in Java. (a) Write a class called Fork with two public methods, ForkpickUp and ForkputDown. The methods should take no arguments and return no result. An instance of Fork should act as a lock to prevent concurrent access. In other words, once ForkpickUp has been called, all further calls to ForkpickUp should block until ForkputDown is called; when ForkputDown is called, one caller (if any) who is blocked should proceed. (b) Write a class called Players which inherits from the Thread class and implements the abstract method run. The Player class should have a single constructor which takes two Fork objects, one representing the fork to the Player’s left, and one to the right. When run, an instance of Player should think for ten seconds, eat for ten seconds and think for ten seconds before terminating.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY