Question II This question carries 50% of the marks for this assignment. This question is about...
This question carries 50% of the marks for this assignment.
This question is about avoiding race condition by using synchronization mechanism provided by the JAVA programming language. We provided you with a Netbeans JAVA project. The project idea is as follows: we want to merge the content of four files into a single file, as follows. Below is the content of all four files:
F1 content: 1 1 1 1
F2 content: 2 2 2 2
F3 content: 3 3 3 3
F4 content: 4 4 4 4
After merging them into the Sink file, we expect the following content in the sink file:1234123412341234
We want to read from each file only one integer value at a time (starting form file number 1, number 2 and so on) and write theses integers values ( in the same order we read them) into a specific sink file, we want to repeat it until all file files are empty.
Please note that all files have the same number of integers.
We have provided you with a template project that needs to be modified to accomplish the above task correctly.
The project is composed of the following classes including four text files:
Four text files called “f1.txt”, “f2.txt”, “f3.txt” and “f4.txt”, each file has a sequence of integer corresponding its name, for instance “f2.txt” contains a sequence of integers all are 2.
The following JAVA source code files are included in the NetBeans projects:
WriteToFile: A helper class to write into a file.
SyncWriteToFile: which control the access to the file, it does so by aggregating an object of the class “WriteToFile”
MergeFiles that extends Thread: it is intended to read all integers form a specific file and use an object of “SyncWriteToFile” to write them into the sink file at the appropriate place.
TMA_Tm298_SummerEgJo: contains the main method to test the program
Read the source code of the above classes carefully and run the project. You will discover that the content of the sink file is not as expected and each time you run it you got a different content. Provide screen shots form running the project without any modification. Provide convincing justification, why you got these results. [15 marks]
In order to get the expected sink file content, you need to modify the project as follows:
You can do so by first identifying the shared resources and then the critical section code in the project. [10 marks]. Then you need to change the critical section code so that the sink file contains the following result no matter how many times you run the project. The sink file correct content is :1234123412341234. [25 marks]
You are sked to submit the whole project (as one zip file) after all modification.