Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

The Java-based solution to the Readers-Writers problem does not prevent waiting writers from starving: If the database is currently being read and there is a

The Java-based solution to the Readers-Writers problem does not prevent waiting writers from starving: If the database is currently being read and there is a waiting writer, subsequent readers will be allowed to read the database before the writer can write. Your task now is to prevent starvation of waiting writers. We will assume that in the application there are far more readers than writers, so your solution need not worry about starvation of readers. Your solution should use Java synchronization primitives for mutual exclusion & condition synchronization. You cannot use semaphores. Test your program creating twelve reader threads and three writer threads. Below are the given files. Edit: I'm in Fundaments of Operating Systems. If there is something missing from my question, please comment with something more specific than "Insufficient knowledge" so that I can update the question accordingly. I have no idea what that means, but if it helps, I am supposed to edit these files to do what the instructions above state. Thank you! Edit: I found another file in the folder that I thought I'd uploaded. One of these is meant to be sort of an example, but I am lost.

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

2 Database.java 5 Epublic class Database public Database readerCount-0 dbReading -false dbWriting -false; 10 12 13 14 15 16 public static void napping) /readers and writers wil1 call int sleepTime (int) NAP_TIMEMath. random ) try Thread.sleep (sleepTime 1000) catch (InterruptedException e) public synchronized int startReadreader will cal1 this wh ing 19 while (dbWritingtrue) try wait catch (InterruptedException e) 23 24 25 26 27 28 29 30 31 32 ++readerCount; if (readerCount1) if I am the first reader tell all others dbReading -true // that the database is being read return readerCount public synchronized int endRead) // reader will call this when they --readerCount if (readerCount-= 0) // if I am the last reader tell all others // that the database is no longer being read dbReadingfalse notifyAll ) 34 35 36 37 38 39 40 System.out.println ("Reader Count-"+ readerCount) return readerCount; public synchronized void startWrite) writer will call this whe rt writi 42 43 while (dbReading-true!! dbwriting-true ) { try wait) catch (InterruptedException e) ( 45 4 6 47 48 49 50 51 52 53 54 dbwriting = true ; once there are either no readers or riters / indicate that the database is being written public synchronized void endwrite) t 7/ writer wil1 call this when ng dbWritingfalse; notifyAll ); /the number of active readers private int readerCount; private boolean dbReading; private boolean dbWriting; private static final int NAP. TIME = 5; 56 57 58 Elags to indicate whether the database is // being read or written 60 2 Database.java 5 Epublic class Database public Database readerCount-0 dbReading -false dbWriting -false; 10 12 13 14 15 16 public static void napping) /readers and writers wil1 call int sleepTime (int) NAP_TIMEMath. random ) try Thread.sleep (sleepTime 1000) catch (InterruptedException e) public synchronized int startReadreader will cal1 this wh ing 19 while (dbWritingtrue) try wait catch (InterruptedException e) 23 24 25 26 27 28 29 30 31 32 ++readerCount; if (readerCount1) if I am the first reader tell all others dbReading -true // that the database is being read return readerCount public synchronized int endRead) // reader will call this when they --readerCount if (readerCount-= 0) // if I am the last reader tell all others // that the database is no longer being read dbReadingfalse notifyAll ) 34 35 36 37 38 39 40 System.out.println ("Reader Count-"+ readerCount) return readerCount; public synchronized void startWrite) writer will call this whe rt writi 42 43 while (dbReading-true!! dbwriting-true ) { try wait) catch (InterruptedException e) ( 45 4 6 47 48 49 50 51 52 53 54 dbwriting = true ; once there are either no readers or riters / indicate that the database is being written public synchronized void endwrite) t 7/ writer wil1 call this when ng dbWritingfalse; notifyAll ); /the number of active readers private int readerCount; private boolean dbReading; private boolean dbWriting; private static final int NAP. TIME = 5; 56 57 58 Elags to indicate whether the database is // being read or written 60

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 22nd European Conference Adbis 2018 Budapest Hungary September 2 5 2018 Proceedings Lncs 11019

Authors: Andras Benczur ,Bernhard Thalheim ,Tomas Horvath

1st Edition

3319983970, 978-3319983974

More Books

Students explore these related Databases questions