Question: The program in which we create objects and threads related to five time prayers: Fair, Zuhur, Asar, Maghrib and Isha. The Program consists of three

 The program in which we create objects and threads related tofive time prayers: Fair, Zuhur, Asar, Maghrib and Isha. The Program consists

The program in which we create objects and threads related to five time prayers: Fair, Zuhur, Asar, Maghrib and Isha. The Program consists of three classes: Callme, Caller, and Prayers. Complete program is given below: class Callme { void call(String msg) { System.out.print("[" + msg); try { Thread sleep(1000); } catch(InterruptedException e) { System.out.println("Interrupted"); System.out.println("]"); } class Caller implements Runnable { String msg; Callme target; Thread t; public Caller(Callme targ, String s) { target = targ; msg=s; t= new Thread(this); t.starto; } public void run() { target.call(msg); } } class Prayers { public static void main(String args[]) { Callme target = new Callmet); Caller obl = new Caller(target, "Fajar"); Caller ob2 = new Caller(target, "Zuhr"); Caller ob3 = new Caller(target, "Asar"); Caller ob4 = new Caller(target, "Maghrib"); Caller ob5 = new Caller(target, "Isha"); try { obl.t.join(); ob2.t.join(); ob3.t.ioino; 0b4. t.join(); ob5.t.join(); catch(InterruptedException e) { System.out.println("Interrupted"); } } The Output of the above program is as follows: C:\Users\janna\Desktop\Programming in Java\Source code\Final Exam>java Prayers [Maghrib[Isha[Zuhr[Fajar[Asar] ] ] There is a race condition in above program that's why the output is not in sequential order. What need to be done in the above program so that we can get the desired output as shown below. C:\Users\janna\Desktop\Programming in Java\Source code\Final Exam>java [Fajar] [Zuhr] [Asar] [Maghrib] [Isha]

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!