diff --git a/src/main/java/fi/utu/tech/threadrunner2/assignment/Task1UsingThreadDistributor.java b/src/main/java/fi/utu/tech/threadrunner2/assignment/Task1UsingThreadDistributor.java index 27b08531462ef824cfd9d0c648997a4ea54f7887..b7302e7d706da4d544931f3b252a0777950f2c50 100644 --- a/src/main/java/fi/utu/tech/threadrunner2/assignment/Task1UsingThreadDistributor.java +++ b/src/main/java/fi/utu/tech/threadrunner2/assignment/Task1UsingThreadDistributor.java @@ -16,10 +16,16 @@ public class Task1UsingThreadDistributor implements Runnable,Distributor{ public Task1UsingThreadDistributor(Mediator mediator, ControlSet control) { this.mediator = mediator; this.control = control; - this.saie1 = new Saie(mediator,control); - mediator.registerThread(saie1.hashCode(), "Luomus");//Kaikki muu toiminnallisuus paitsi laskeminen tähän luokkaan - this.saie2 = new Saie(mediator,control); - mediator.registerThread(saie2.hashCode(), "Luomus2"); + this.saikeet= new Saie[control.getThreadCount()]; + for(int i=0; i<control.getThreadCount(); i++) { + saikeet[i]=new Saie(mediator, control); + mediator.registerThread(saikeet[i].hashCode(), "Thread"); + } + + //this.saie1 = new Saie(mediator,control); + //mediator.registerThread(saie1.hashCode(), "Luomus");//Kaikki muu toiminnallisuus paitsi laskeminen tähän luokkaan + //this.saie2 = new Saie(mediator,control); + //mediator.registerThread(saie2.hashCode(), "Luomus2"); } @@ -32,6 +38,22 @@ public class Task1UsingThreadDistributor implements Runnable,Distributor{ //mediator.setRunStatus("Created", this.hashCode()); } public void run() {//pystyttäisiinkö vaan while notifyAll metodeilla + boolean x=true; + for(Saie saie : saikeet) { + mediator.setRunStatus("Running",saie.hashCode()); + } + for(Saie saie : saikeet) { + saie.run(); + } + //while(x) { + //for(Saie saie : saikeet) { + + //saie.run(mediator.getWorkSlice(control.getBlockSize()),control.getBlockSize()); + //} + //if(mediator.getWorkSlice(control.getBlockSize()).isEmpty()) { + //x=false; + //} + //} //mediator.registerThread(this.hashCode(), "Jotain1"); //for(Thread saie : saikeet) { //mediator.setRunStatus("Running", this.hashCode()); @@ -45,10 +67,10 @@ public class Task1UsingThreadDistributor implements Runnable,Distributor{ //sleep(100); //} //mediator.setRunStatus("Ended", this.hashCode()); - mediator.setRunStatus("Testi", saie1.hashCode()); - saie1.run(mediator.getWorkSlice(control.getBlockSize()), control.getBlockSize()); - mediator.setRunStatus("Testi", saie2.hashCode()); - saie2.run(mediator.getWorkSlice(control.getBlockSize()),control.getBlockSize()); + //mediator.setRunStatus("Testi", saie1.hashCode()); + //saie1.run(mediator.getWorkSlice(control.getBlockSize()), control.getBlockSize()); + //mediator.setRunStatus("Testi", saie2.hashCode()); + //saie2.run(mediator.getWorkSlice(control.getBlockSize()),control.getBlockSize()); } }