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
No related tags found
No related merge requests found
......@@ -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
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment