From 2dee7ee2f2f94020cf591e6a4dad96dd84179f77 Mon Sep 17 00:00:00 2001
From: nuklin <nuklin@utu.fi>
Date: Fri, 26 Nov 2021 13:18:04 +0200
Subject: [PATCH] =?UTF-8?q?Koitin=20lis=C3=A4t=C3=A4=20for-loop=20toteutuk?=
 =?UTF-8?q?sen.=20Saie=20luokan=20run-metodin=20muokkauksen=20j=C3=A4lkeen?=
 =?UTF-8?q?=20vastannee=20masteria?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../Task1UsingThreadDistributor.java          | 38 +++++++++++++++----
 1 file changed, 30 insertions(+), 8 deletions(-)

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 27b0853..b7302e7 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());
 		}
 		
 	}
-- 
GitLab