Question: Modify the following code using multi-threading Java implementation of the system. At the minimum: a. Each station should be implemented using a dedicated thread b.

Modify the following code using multi-threading Java implementation of the system.

At the minimum:

a. Each station should be implemented using a dedicated thread

b. The simulation control should be implemented using a dedicated thread.

c. The carrier should be a shared resource (as the bounded Q in the threads example).

d. Threads should have provisions for synchronization, avoidance of race conditions and deadlocks.

e. Threads cannot communicate with a other threads via inter-process communication (except for using locks and synch.)

The program should use the following class diagram.  Modify the following code using multi-threading Java implementation of the system. //CSMACD Class import java.util.Random; public class CSMACD { static boolean randomBool() { Random ran=new Random(); int num=ran.nextInt(); return num%2==1; } public static void main(String[] args) { Station s1,s2,s3; double r1, r2 , r3, r4; boolean carrierStatus; for(int i = 0; irandomBool(); r1 = Math.random(); s1 = new Station((int) r1,carrierStatus); carrierStatus = randomBool(); r1=Math.random(); s2=new Station((int) r1,carrierStatus); carrierStatus = randomBool(); r1=Math.random(); s3=new Station((int) r1,carrierStatus); System.out.println("sending message from s1 to s2"); if(s1.isCarrierStatus() && s2.isCarrierStatus()) { System.out.println("Collision occur! Transmiss stop!"); r4 = Math.random(); try { Thread.sleep((long) r4); } catch (InterruptedException e) { e.printStackTrace(); } } else if(s1.isCarrierStatus()==false&&s2.isCarrierStatus()==false) { r2=Math.random(); s2.setMessage((int) r2); System.out.println("Data has been transmited successfully!"); } else { System.out.println("s1 or s2 is looking busy!"); r3=Math.random(); try { Thread.sleep((long) r3); } catch (InterruptedException e) { e.printStackTrace(); } } System.out.println("sending message from s2 to s3"); if(s2.isCarrierStatus()&&s3.isCarrierStatus()) { System.out.println("Collision occur! Transmiss stop!"); r4 = Math.random(); try { Thread.sleep((long) r4); } catch (InterruptedException e) { e.printStackTrace(); } } else if(s2.isCarrierStatus()==false&&s3.isCarrierStatus()==false) { r2=Math.random(); s3.setMessage((int) r2); System.out.println("Data has been transmited successfully!"); } else { System.out.println("s2 or s3 is looking busy!"); r3=Math.random(); try { Thread.sleep((long) r3); } catch (InterruptedException e) { e.printStackTrace(); } } System.out.println("sending message from s3 to s1"); if(s3.isCarrierStatus()&&s1.isCarrierStatus()) { System.out.println("Collision occur! Transmiss stop!"); r4=Math.random(); try { Thread.sleep((long) r4); } catch (InterruptedException e) { e.printStackTrace(); } } else if(s3.isCarrierStatus()==false&&s1.isCarrierStatus()==false) { r2=Math.random(); s1.setMessage((int) r2); System.out.println("Data has been transmited successfully!"); } else { System.out.println("s3 or s1 is looking busy!"); r3=Math.random(); try { Thread.sleep((long) r3); } catch (InterruptedException e) { e.printStackTrace(); } } } } } } //Station Class  public class Station { private int message; private boolean carrierStatus; private int reveivedMessage; public Station(int message, boolean carrierStatus) { this.message = message; this.carrierStatus = carrierStatus; } public int getMessage() { return message; } public void setMessage(int message) { this.message = message; } public boolean isCarrierStatus() { return carrierStatus; } public void setCarrierStatus(boolean carrierStatus) { this.carrierStatus = carrierStatus; } public int getReveivedMessage() { return reveivedMessage; } public void setReveivedMessage(int reveivedMessage) { this.reveivedMessage = reveivedMessage; } } 

Simulation +main(args: Stringl): void +check station_status(): void tupdate_station_status(): void +update_carrier_status(): void Class Diagram Station Carrier -station status: boolean probability double -R2_start transmission: ticks -R3_delay1: ticks -R4_delay2: ticks Set/get parameters R5_carrier length: met +set/get parameters

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!