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 that 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
Java Threads
Describe and explain in detail the producerconsumer principle for concurrent programming as we studied in this course Please use your own explanation don't copy and paste external resources here that will get zero credit
Choose one of the mechanisms we use studied to synchronize one producer and one consumer thread and write an example demonstrator with classes called Producer and Consumer working that shows they are synchronized on a producing and consuming a sequentially increasing integer producer produces from to and consumer consumes and set the buffer to after to consuming it
Explain in your comments in the Java code the most important aspects that enabled synchronization between the threads in step above.
Java Streams and Lambda Functions
Write a program using Java Streams and Lambda functions and mapreduce paradigm that:
Generates random integers in the range to
Counts the frequency of occurrence of each number.
Prints a display of how many times each number was generated in the range
Repeat the experiment again by performing the same steps but increasing the size from to and int report results using the print function.
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
