Select Git revision
Forked from
Eckl, Máté / Prog3 laborok
Source project has a limited visibility.
Fifo.java 593 B
import java.util.ArrayList;
public class Fifo{
protected ArrayList<String> s;
{
s = new ArrayList<>(10); //csak azért, hogy használjak már inicializáló blokkot is
}
public synchronized void put(String e) throws InterruptedException
{
if(s.size()>=10)
{
this.wait();
}
this.notifyAll();
s.add(e);
System.out.println("produced" + " " + e + " " +
System.currentTimeMillis());
}
synchronized String get() throws InterruptedException
{
if(s.size()<=0)
{
this.wait();
}
this.notifyAll();
String ret=s.get(0);
s.remove(ret);
return ret;
}
}