Question: Exercise 4 Write a program to create two threads using anonymous inner classes that implement Runnable in the main program. The first thread must generate
Exercise 4 Write a program to create two threads using anonymous inner classes that implement Runnable in the main program. The first thread must generate 10 random numbers in the range from to 100 and the second thread finds the sum of the 10 random numbers that are generated by the first thread and prints the sum value Main thread has to stop execution only after the first thread and the second thread complete their execution Hints: . Use PipedOutputStream and PipedInputStream 2. Use DataOutputStream, DatalnputStream to 3. Use Dr. Imran's slides on threads to understand for thread communication write integer and read integer thread communication using pipes Sample output: Thread 1 generating random numbers Random value87 Random value70 Random value-55 Random value21 Random value2 Random value = 89 Random value28 Random value60 Random value40 Random value72 Thread 2 printing sum of all the random numbers524 Note: Make sure to make use of DataOutputStream, DataInputStream
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
