Skip to content
Snippets Groups Projects
Commit 1b717f4d authored by Eckl, Máté's avatar Eckl, Máté
Browse files

5. labor összes feladat kész

A 6. feladatot kicsit hamarabb csináltam meg, mert én úgy jobban szeretem, úgyhogy az a rész itt már nem változott.
parent 2547f25e
Branches
Tags 0.12.6
No related merge requests found
...@@ -2,12 +2,13 @@ public class Application { ...@@ -2,12 +2,13 @@ public class Application {
public static void main(String args[]) throws InterruptedException public static void main(String args[]) throws InterruptedException
{ {
Fifo storage = new Fifo(); Fifo storage = new Fifo();
Producer prod = new Producer(storage, "producer", 250); Thread threads[] = new Thread[7];
Consumer con = new Consumer(storage, "consumer", 500); 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); for(int i=0;i<7;i++)
Thread t2 = new Thread(con); threads[i].start();
t1.start();
t2.start();
} }
} }
\ No newline at end of file
...@@ -7,23 +7,21 @@ public class Fifo{ ...@@ -7,23 +7,21 @@ public class Fifo{
} }
public synchronized void put(String e) throws InterruptedException 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.wait();
} this.notify();
this.notifyAll();
s.add(e); s.add(e);
System.out.println("produced" + " " + e + " " + System.out.println("produced" + " " + e + " " +
System.currentTimeMillis()); System.currentTimeMillis() % 10000);
} }
synchronized String get() throws InterruptedException synchronized String get() throws InterruptedException
{ {
if(s.size()<=0) System.out.println("get: " + Thread.currentThread());
{ while(s.size()<=0)
this.wait(); this.wait();
} this.notify();
this.notifyAll();
String ret=s.get(0); String ret=s.get(0);
s.remove(ret); s.remove(ret);
return ret; return ret;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment