Skip to content
Snippets Groups Projects
Commit 2dee7ee2 authored by nuklin's avatar nuklin
Browse files

Koitin lisätä for-loop toteutuksen. Saie luokan run-metodin muokkauksen jälkeen vastannee masteria

parent 0854901e
No related branches found
No related tags found
No related merge requests found
...@@ -16,10 +16,16 @@ public class Task1UsingThreadDistributor implements Runnable,Distributor{ ...@@ -16,10 +16,16 @@ public class Task1UsingThreadDistributor implements Runnable,Distributor{
public Task1UsingThreadDistributor(Mediator mediator, ControlSet control) { public Task1UsingThreadDistributor(Mediator mediator, ControlSet control) {
this.mediator = mediator; this.mediator = mediator;
this.control = control; this.control = control;
this.saie1 = new Saie(mediator,control); this.saikeet= new Saie[control.getThreadCount()];
mediator.registerThread(saie1.hashCode(), "Luomus");//Kaikki muu toiminnallisuus paitsi laskeminen tähän luokkaan for(int i=0; i<control.getThreadCount(); i++) {
this.saie2 = new Saie(mediator,control); saikeet[i]=new Saie(mediator, control);
mediator.registerThread(saie2.hashCode(), "Luomus2"); 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{ ...@@ -32,6 +38,22 @@ public class Task1UsingThreadDistributor implements Runnable,Distributor{
//mediator.setRunStatus("Created", this.hashCode()); //mediator.setRunStatus("Created", this.hashCode());
} }
public void run() {//pystyttäisiinkö vaan while notifyAll metodeilla 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"); //mediator.registerThread(this.hashCode(), "Jotain1");
//for(Thread saie : saikeet) { //for(Thread saie : saikeet) {
//mediator.setRunStatus("Running", this.hashCode()); //mediator.setRunStatus("Running", this.hashCode());
...@@ -45,10 +67,10 @@ public class Task1UsingThreadDistributor implements Runnable,Distributor{ ...@@ -45,10 +67,10 @@ public class Task1UsingThreadDistributor implements Runnable,Distributor{
//sleep(100); //sleep(100);
//} //}
//mediator.setRunStatus("Ended", this.hashCode()); //mediator.setRunStatus("Ended", this.hashCode());
mediator.setRunStatus("Testi", saie1.hashCode()); //mediator.setRunStatus("Testi", saie1.hashCode());
saie1.run(mediator.getWorkSlice(control.getBlockSize()), control.getBlockSize()); //saie1.run(mediator.getWorkSlice(control.getBlockSize()), control.getBlockSize());
mediator.setRunStatus("Testi", saie2.hashCode()); //mediator.setRunStatus("Testi", saie2.hashCode());
saie2.run(mediator.getWorkSlice(control.getBlockSize()),control.getBlockSize()); //saie2.run(mediator.getWorkSlice(control.getBlockSize()),control.getBlockSize());
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment