Question: Write 3 Runnable thread object types as follows:A Java class Generator that inherits from the Runnable interface. Override and implement the classes run ( )
Write Runnable thread object types as follows:A Java class Generator that inherits from the Runnable interface. Override and implement the classes run method in which the thread runs every milliseconds and fills the Integer array with random numbers of integer type. The thread should only fill the array if it is empty otherwise it must wait. A Java class Sorter that inherits from the Runnable interface. Override and implement the classes run method in which the thread runs every milliseconds and sorts the array or similar data structure filled by the Generator thread. It must only attempt to perform the sort if the array is of size and has been freshly generated by the Generator thread. A Java class Drainer that inherits from the Runnable interface. Override and implement the classes run method in which the thread runs every milliseconds and clears the array sorted by the Sorter thread. It must only attempt to perform the clear operation after the filling was done by Generator thread and sorting by the Sorter thread was done by the first threads. Create a class called Simulation that contains:A private Integer ArrayList or similar data structure to an array type to store Integers.A public synchronized print method to the Simulation class to print the contents of the array in a single line with one whitespace between each number. Call this print method after each thread does its job once. A public method called runsim in which one instance of each of the thread types above ab and c are created. The threads must then be executed using the Thread Executor service as we studied in class. Let the simulation run such each thread runs times only. Design a thread synchronization mechanism using the book examples that ensures that the threads execute sequentially in a synchronized manner one after the other ie first the generator thread runs, then the sorter thread runs and then finally the drain thread, after which the cycle repeats. Create a class with function main which creates a Simulation and invokes runsim
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
