Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Preferably done in Java. Also what would one notice as far as differences betwee

ID: 3843139 • Letter: P

Question

Preferably done in Java. Also what would one notice as far as differences between the runs, and how did the constant used affect the output... in what ways? Could you include brief comments explaining parts of the code and what purpose they have?

Make a C/C++ or Java program which creates two child processes/threads. Each child has a loop in it (do the loop 10 times). The loop consists of a print statement and a sleep (x) statement (where x is a random number from 1 to 3; you must compute a new random number for each call. If you do not know how to create child processes in Cor a thread in Java, you can look on the Internet to find examples

Explanation / Answer

Answer: Explanined everything in code comment, Created the two threads and printing the i value in each thread with thread name to differentiate between thread execution. import java.util.Random; public class Mythread { public static void main(String[] args) { /** Creating thread 1 **/ Runnable r = new Runnable1(); Thread t = new Thread(r); /** Creating thread 2 **/ Runnable r2 = new Runnable2(); Thread t2 = new Thread(r2); /** Starting thread 1 and thread 2**/ t.start(); t2.start(); } } class Runnable2 implements Runnable{ public void run(){ /** looping 10 times using for loop **/ for(int i=0;i