Skip to content
Snippets Groups Projects
Select Git revision
  • 2547f25eb5f01e9d4b1b36d4b26cc04c2eae5672
  • master default
2 results

Fifo.java

Blame
  • 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;
    	}
    }