public class Producer implements Runnable{

    private String innerString;
    private int indexOfPrint = 0;
    private Fifo selfFifo = null;

    private int sleepTime=1000;

    public Producer(String arg1, Fifo f,int n){
        innerString=arg1;
        indexOfPrint=0;
        selfFifo=f;
        sleepTime=n;
    }

    /*void go() throws InterruptedException {
        while(true){
            Thread.sleep(1000);
            String systemTime= String.valueOf(System.currentTimeMillis());
            systemTime=systemTime.substring(systemTime.length()-5,systemTime.length());
            System.out.println(innerString+" "+indexOfPrint+" "+systemTime);
            indexOfPrint++;
        }
    }*/

    @Override
    public void run() {
        try {
            while (true) {
                Thread.sleep(sleepTime);
                String systemTime = String.valueOf(System.currentTimeMillis());
                systemTime = systemTime.substring(systemTime.length() - 5);

                if(selfFifo!=null){
                    selfFifo.put(innerString + " " + indexOfPrint);
                }
                System.out.println(innerString + " " + indexOfPrint + " " + systemTime);
                indexOfPrint++;
            }
        } catch (InterruptedException e) {
            System.out.println(innerString + " megszakítva");
        }
    }
}
