From 1b717f4de96ad88fe496f208c252c196b88c1c65 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Eckl=2C=20M=C3=A1t=C3=A9?= <ecklm@sch.bme.hu>
Date: Mon, 12 Oct 2015 22:43:30 +0200
Subject: [PATCH] =?UTF-8?q?5.=20labor=20=C3=B6sszes=20feladat=20k=C3=A9sz?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

A 6. feladatot kicsit hamarabb csináltam meg, mert én úgy jobban szeretem, úgyhogy az a rész itt már nem változott.
---
 5. labor/Producer/src/Application.java | 13 +++++++------
 5. labor/Producer/src/Fifo.java        | 16 +++++++---------
 2 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/5. labor/Producer/src/Application.java b/5. labor/Producer/src/Application.java
index 9e702d5..238560f 100644
--- a/5. labor/Producer/src/Application.java	
+++ b/5. labor/Producer/src/Application.java	
@@ -2,12 +2,13 @@ public class Application {
 	public static void main(String args[]) throws InterruptedException
 	{
 		Fifo storage = new Fifo();
-		Producer prod = new Producer(storage, "producer", 250);
-		Consumer con = new Consumer(storage, "consumer", 500);
+		Thread threads[] = new Thread[7];
+		for(int i=0;i<3;i++)
+			threads[i] = new Thread(new Producer(storage, "producer", (int) Math.random()));
+		for(int i=3;i<7;i++)
+			threads[i] = new Thread(new Consumer(storage, "consumer", (int) Math.random()));
 		
-		Thread t1 = new Thread(prod);
-		Thread t2 = new Thread(con);
-		t1.start();
-		t2.start();
+		for(int i=0;i<7;i++)
+			threads[i].start();
 	}
 }
\ No newline at end of file
diff --git a/5. labor/Producer/src/Fifo.java b/5. labor/Producer/src/Fifo.java
index d4d4bfc..4dd62a4 100644
--- a/5. labor/Producer/src/Fifo.java	
+++ b/5. labor/Producer/src/Fifo.java	
@@ -7,23 +7,21 @@ public class Fifo{
 	}
 	public synchronized void put(String e) throws InterruptedException
 	{
-		if(s.size()>=10)
-		{
+		System.out.println("put: " + Thread.currentThread());
+		while(s.size()>=10)
 			this.wait();
-		}
-		this.notifyAll();
+		this.notify();
 		s.add(e);
 		System.out.println("produced" + " " + e + " " + 
-							System.currentTimeMillis());
+							System.currentTimeMillis() % 10000);
 	}
 	
 	synchronized String get() throws InterruptedException
 	{
-		if(s.size()<=0)
-		{
+		System.out.println("get: " + Thread.currentThread());
+		while(s.size()<=0)
 			this.wait();
-		}
-		this.notifyAll();
+		this.notify();
 		String ret=s.get(0);
 		s.remove(ret);
 		return ret;
-- 
GitLab