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 3 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 5 milliseconds and fills the Integer array with 10 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 5 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 10 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 5 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 2 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 3 thread types above (1a,1b, and 1c) 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 10 times only.
Design a thread synchronization mechanism using the book examples that ensures that the 3 threads execute sequentially in a synchronized manner one after the other - i.e., 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 producer-consumer 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 1 to 10 and consumer consumes and set the buffer to 0 after to consuming it.
Explain in your comments in the Java code the most important aspects that enabled synchronization between the 2 threads in step 2 above.
Java Streams and Lambda Functions
Write a program using Java Streams and Lambda functions and map-reduce paradigm that:
Generates 100 random integers in the range 1 to 10.
Counts the frequency of occurrence of each number.
Prints a display of how many times each number was generated in the range 1-10.
Repeat the experiment again by performing the same 3 steps but increasing the size from 100, to 1000,100,000, and 1,000,000 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 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!