A health center has employed two doctors that examine and treat at most 25 patie
ID: 3818143 • Letter: A
Question
A health center has employed two doctors that examine and treat at most 25 patients in a day.
A patient is examined and treated by any one of the two doctors. Each patient has to register his name so that the doctors can examine and treat the patient on first-come-first-serve bases.
Part a: For the scenario mentioned above, develop a program that creates patients and doctors (both are threads). Patients register in a queue and the doctors pick patient from the same queue on first-come-first-serve bases and examine and treat them. Use the queue that is not thread safe (For example ArrayDeque). Make sure your program has no synchronization issues and test run your code for the following test cases.
Queue (of patients) is full. (Make an assumption that if there are 10 patients in the queue then the queue is full). The patients competing to register in the queue have to wait until queue is not full. If the queue changes its state from full to not full, queue has to notify all waiting threads (patients).
Queue (of patients) is empty. The doctors have to wait until queue is not empty. If the queue changes its state from empty to not empty, queue has to notify all waiting threads (doctors).
Part b: Use the queue that is thread safe (For example, ArrayBlockedQueue) and check if your solution has synchronization issues. (Make sure that you solution does not provide synchronized methods or synchronized blocks)
Explanation / Answer
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.