Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Security

Authors: Alfred Basta, Melissa Zgola

1st Edition

1435453905, 978-1435453906

More Books

Students also viewed these Databases questions

Question

finstrincerisx finstrincerisx

Answered: 1 week ago