Universität Paderborn - Home Universität Paderborn
Die Universität der Informationsgesellschaft

Parallel Programming WS 2014/2015 - File Producer.java

public class Producer extends Thread {
   private int producerIndex;
   private Buffer buffer;
   
   static int elemcount = 0;
   public Producer(int i, Buffer b) {
        producerIndex = i;
	buffer=b;
    }

    void produceElement() {
        buffer.put(++elemcount);
    }

    public void run() {
        while (true) {
            produceElement();
            try {
                Thread.sleep((int)(Math.random() * 2000));
            } catch (InterruptedException e) {/* ok to ignore */}
        }
    }

}

Generiert mit Camelot | Probleme mit Camelot? | Geändert am: 20.11.2014