Apr 21st, 2014
Price: $5 USD

Question description

  1. We have discussed in the class the implementation of the readers-writers problem in Java. However, the read and write tasks of the reader thread and the writer thread are not given. Implement these tasks in Java as reading and writing of a file named counter.txt, which contains an integer counter. 
    reader thread
  2. reads the counter from the file, and
  3. prints out its thread name and the value of the counter.

writer threadincrements the value of the counter in the file,prints out its thread name and the new value of the counter.Each thread repeats its task indefinitely in a random amount of time between 0 and 3000 ms. Your main program should create 20 reader threads and 3 writer threads.

Besides the source code, turn in scripts showing that you compile and run the program successfully. Turn in also some sample outputs. 

( 20 points ) We discussed in class the readers-writers problem with writers priority, which can be solved in guarded commands:void reader() { when ( writers == 0 ) [ readers++; ] //read [readers--;] }    void writer() { [writers++;] when ( (readers == 0) && (active_writers == 0) )[ active_writers++; ] //write [writers--; active_writers--;] } Here writers represents the number of threads that are either writing or waiting to write. The variable active_writers represents the number of threads ( 0 or 1 ) that are currently writing.Implement the solution using Java threads. Again simulate the tasks by reading from and writing to a file named counter.txt as in the previous problem.Besides the source code, turn in scripts showing that you compile and run the program successfully. Turn in also some sample outputs. 

Tutor Answer

(Top Tutor) cybermaniax
School: Duke University

Studypool has helped 1,244,100 students

Review from student
" Wow this is really good.... didn't expect it. Sweet!!!! "
Ask your homework questions. Receive quality answers!

Type your question here (or upload an image)

1829 tutors are online

Brown University

1271 Tutors

California Institute of Technology

2131 Tutors

Carnegie Mellon University

982 Tutors

Columbia University

1256 Tutors

Dartmouth University

2113 Tutors

Emory University

2279 Tutors

Harvard University

599 Tutors

Massachusetts Institute of Technology

2319 Tutors

New York University

1645 Tutors

Notre Dam University

1911 Tutors

Oklahoma University

2122 Tutors

Pennsylvania State University

932 Tutors

Princeton University

1211 Tutors

Stanford University

983 Tutors

University of California

1282 Tutors

Oxford University

123 Tutors

Yale University

2325 Tutors