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. A reader thread
reads the counter from the file, and
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 ) [
} void writer()
when ( (readers == 0) && (active_writers == 0) )[
} 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.