Question: Hi, could you please help me out with this programming assignment. It needs to be done in Java and it would be very helpful if

Hi, could you please help me out with this programming assignment. It needs to be done in Java and it would be very helpful if you could add comments.

Description To handle a large amount of data it has been decided to filter the data into separate files. The data is larger than the local storage capacity so all the data cannot be handled at once. In this assignment we are only interested in a concurrent implementation of this filtering. So a number of simplifications have been made to the above scenario. The data is assumed to be integers. The size of the local storage capacity is m (below m is chosen to be 4). The size of the data is n (below n is chosen to be 100m = 400). Any storage needed to handle concurrency correctly is assumed to be negligible compared to n and m, so this is disregarded. The filtering is into k files (below k is chosen to be 2). [Clearly, in a real application m and n would be several magnitudes larger.]

Task Develop a multithreaded program with three concurrent threads, A, B and C. Thread A generates n random integer numbers and writes them into a shared memory with a capacity of m integers. Due to the limited capacity of the shared memory, thread A cannot write all numbers at once. Threads B and C read the integer numbers from the shared memory. Thread B writes the even numbers to th file even-numbers and thread C writes the odd numbers to the file odd-numbers. Every number generated by thread A should be written in one of the two files. No number should be written twice. Choose any method, or combination of methods, for synchronization. To achieve full marks: Encapsulate the synchronized methods and the shared memory into one structure. Avoid busy waiting. Avoid static variables.

Extension task Write code that could easily be modified to cater for different values of m, n, and k above. For k = 3 you may consider the three classes of odd numbers, even numbers, and multiples of 3. Note that these are non-disjoint: numbers belonging to more than one class can be filtered into any of these but should still only appear in one of the output files.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!